<!-- This HTML file has been created by texi2html 1.30
     from ../r4rs.texi on 14 July 1994 -->

<TITLE>Scheme - Standard procedures</TITLE>
<P>Go to the <A HREF="r4rs_7.htm">previous</A>, <A HREF="r4rs_9.htm">next</A> section.<P>
<H1><A NAME="SEC45" HREF="r4rs_toc.htm#SEC45">Standard procedures</A></H1>
<A NAME="IDX163"></A>
<A NAME="IDX164"></A>
<P>
This chapter describes Scheme's built-in procedures.  The initial (or
"top level") Scheme environment starts out with a number of variables
bound to locations containing useful values, most of which are primitive
procedures that manipulate data.  For example, the variable <CODE>abs</CODE>
is
<A NAME="IDX165"></A>
bound to (a location initially containing) a procedure of one argument
that computes the absolute value of a number, and the variable <CODE>+</CODE>
<A NAME="IDX166"></A>
is bound to a procedure that computes sums.
<P>
<H2><A NAME="SEC46" HREF="r4rs_toc.htm#SEC46">Booleans</A></H2>
<P>
The standard boolean objects for true and false are written as
<CODE>#t</CODE> and <CODE>#f</CODE>.
<A NAME="IDX168"></A>
<A NAME="IDX167"></A>
What really matters, though, are the objects that the Scheme conditional
expressions (<CODE>if</CODE>, <CODE>cond</CODE>, <CODE>and</CODE>, <CODE>or</CODE>, <CODE>do</CODE>)
treat as true or false.
<A NAME="IDX170"></A>
<A NAME="IDX171"></A>
<A NAME="IDX172"></A>
<A NAME="IDX173"></A>
<A NAME="IDX174"></A>
<A NAME="IDX175"></A>
<A NAME="IDX169"></A>
The phrase "a true value" (or sometimes just "true") means any
object treated as true by the conditional expressions, and the phrase
"a false value" (or "false") means any object treated as false by
the conditional expressions.
<P>
Of all the standard Scheme values, only <CODE>#f</CODE>
counts as false in conditional expressions.
Except for <CODE>#f</CODE>,
all standard Scheme values, including <CODE>#t</CODE>,
pairs, the empty list, symbols, numbers, strings, vectors, and procedures,
count as true.
<P>
<EM>Note:</EM>  In some implementations the empty list counts as false, contrary
to the above.
Nonetheless a few examples in this report assume that the
empty list counts as true, as in [IEEESCHEME].
<P>
<EM>Note:</EM>  Programmers accustomed to other dialects of Lisp should be aware that
Scheme distinguishes both <CODE>#f</CODE> and the empty list from the symbol
<CODE>nil</CODE>.
<A NAME="IDX176"></A>
<P>
Boolean constants evaluate to themselves, so they don't need to be quoted
in programs.
<P>
<PRE>
#t                          =>  #t
#f                          =>  #f
'#f                         =>  #f
</PRE>
<P>
<A NAME="IDX177"></A>
<U>essential procedure:</U> <B>not</B> <I>obj</I><P>
<P>
<CODE>Not</CODE> returns <CODE>#t</CODE> if <VAR>obj</VAR> is false, and returns
<A NAME="IDX178"></A>
<CODE>#f</CODE> otherwise.
<P>
<PRE>
(not #t)                    =>  #f
(not 3)                     =>  #f
(not (list 3))              =>  #f
(not #f)                    =>  #t
(not '())                   =>  #f
(not (list))                =>  #f
(not 'nil)                  =>  #f
</PRE>
<P>
<A NAME="IDX179"></A>
<U>essential procedure:</U> <B>boolean?</B> <I>obj</I><P>
<P>
<CODE>Boolean?</CODE> returns <CODE>#t</CODE> if <VAR>obj</VAR> is either <CODE>#t</CODE> or
<A NAME="IDX180"></A>
<CODE>#f</CODE> and returns <CODE>#f</CODE> otherwise.
<P>
<PRE>
(boolean? #f)               =>  #t
(boolean? 0)                =>  #f
(boolean? '())              =>  #f
</PRE>
<P>
<H2><A NAME="SEC47" HREF="r4rs_toc.htm#SEC47">Equivalence predicates</A></H2>
<P>
A <DFN>predicate</DFN> is a procedure that always returns a boolean
value (<CODE>#t</CODE> or <CODE>#f</CODE>).  An <DFN>equivalence predicate</DFN> is
the computational analogue of a mathematical equivalence relation (it is
symmetric, reflexive, and transitive).  Of the equivalence predicates
described in this section, <CODE>eq?</CODE> is the finest or most
<A NAME="IDX181"></A>
discriminating, and <CODE>equal?</CODE> is the coarsest.  <CODE>Eqv?</CODE> is
<A NAME="IDX183"></A>
<A NAME="IDX182"></A>
slightly less discriminating than <CODE>eq?</CODE>.
<A NAME="IDX184"></A>
<P>
<A NAME="IDX185"></A>
<U>essential procedure:</U> <B>eqv?</B> <I>obj1 obj2</I><P>
<P>
The <CODE>eqv?</CODE> procedure defines a useful equivalence relation on
objects.
<A NAME="IDX186"></A>
Briefly, it returns <CODE>#t</CODE> if <VAR>obj1</VAR> and <VAR>obj2</VAR> should
normally be regarded as the same object.  This relation is left slightly
open to interpretation, but the following partial specification of
<CODE>eqv?</CODE> holds for all implementations of Scheme.
<A NAME="IDX187"></A>
<P>
The <CODE>eqv?</CODE> procedure returns <CODE>#t</CODE> if:
<A NAME="IDX188"></A>
<P>
<UL>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are both <CODE>#t</CODE> or both <CODE>#f</CODE>.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are both symbols and
<P>
<PRE>
(string=? (symbol-&#62;string obj1)
          (symbol-&#62;string obj2))
                            =>  #t
</PRE>
<P>
<EM>Note:</EM>  This assumes that neither <VAR>obj1</VAR> nor <VAR>obj2</VAR> is an "uninterned
symbol" as alluded to in section <A HREF="r4rs_8.htm#SEC49">Symbols</A>.  This report does
not presume to specify the behavior of <CODE>eqv?</CODE> on
implementation-dependent
<A NAME="IDX189"></A>
extensions.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are both numbers, are numerically
equal (see <CODE>=</CODE>, section <A HREF="r4rs_8.htm#SEC50">Numbers</A>), and are either both
<A NAME="IDX190"></A>
exact or both inexact.
<A NAME="IDX192"></A>
<A NAME="IDX191"></A>
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are both characters and are the same
character according to the <CODE>char=?</CODE> procedure (section <A HREF="r4rs_8.htm#SEC57">Characters</A>).
<A NAME="IDX193"></A>
<P>
<LI>both <VAR>obj1</VAR> and <VAR>obj2</VAR> are the empty list.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are pairs, vectors, or strings that denote the
same locations in the store (section <A HREF="r4rs_5.htm#SEC24">Storage model</A>).
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are procedures whose location tags are
equal (section <A HREF="r4rs_6.htm#SEC30">Lambda expressions</A>).
</UL>
<P>
The <CODE>eqv?</CODE> procedure returns <CODE>#f</CODE> if:
<A NAME="IDX194"></A>
<P>
<UL>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are of different types
(section <A HREF="r4rs_5.htm#SEC23">Disjointness of types</A>).
<P>
<LI>one of <VAR>obj1</VAR> and <VAR>obj2</VAR> is <CODE>#t</CODE> but the other is
<CODE>#f</CODE>.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are symbols but
<P>
<PRE>
(string=? (symbol-&#62;string <VAR>obj1</VAR>)
          (symbol-&#62;string <VAR>obj2</VAR>))
                            =>  #f
</PRE>
<P>
<LI>one of <VAR>obj1</VAR> and <VAR>obj2</VAR> is an exact number but the other
is an inexact number.
<P>
<A NAME="IDX195"></A>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are numbers for which the <CODE>=</CODE>
procedure returns <CODE>#f</CODE>.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are characters for which the
<CODE>char=?</CODE>
<A NAME="IDX196"></A>
procedure returns <CODE>#f</CODE>.
<P>
<LI>one of <VAR>obj1</VAR> and <VAR>obj2</VAR> is the empty list but the other
is not.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are pairs, vectors, or strings that denote
distinct locations.
<P>
<LI><VAR>obj1</VAR> and <VAR>obj2</VAR> are procedures that would behave differently
(return a different value or have different side effects) for some arguments.
<P>
</UL>
<P>
<PRE>
(eqv? 'a 'a)                =>  #t
(eqv? 'a 'b)                =>  #f
(eqv? 2 2)                  =>  #t
(eqv? '() '())              =>  #t
(eqv? 100000000 100000000)  =>  #t
(eqv? (cons 1 2) (cons 1 2))=>  #f
(eqv? (lambda () 1)
      (lambda () 2))        =>  #f
(eqv? #f 'nil)              =>  #f
(let ((p (lambda (x) x)))
  (eqv? p p))               =>  #t
</PRE>
<P>
The following examples illustrate cases in which the above rules do
not fully specify the behavior of <CODE>eqv?</CODE>.  All that can be said
<A NAME="IDX197"></A>
about such cases is that the value returned by <CODE>eqv?</CODE> must be a
<A NAME="IDX198"></A>
boolean.
<P>
<PRE>
(eqv? "" "")                =>  <EM>unspecified</EM>
(eqv? '#() '#())            =>  <EM>unspecified</EM>
(eqv? (lambda (x) x)
      (lambda (x) x))       =>  <EM>unspecified</EM>
(eqv? (lambda (x) x)
      (lambda (y) y))       =>  <EM>unspecified</EM>
</PRE>
<P>
The next set of examples shows the use of <CODE>eqv?</CODE> with procedures
<A NAME="IDX199"></A>
that have local state.  <CODE>Gen-counter</CODE> must return a distinct
<A NAME="IDX200"></A>
procedure every time, since each procedure has its own internal counter.
<CODE>Gen-loser</CODE>, however, returns equivalent procedures each time,
since
<A NAME="IDX201"></A>
the local state does not affect the value or side effects of the
procedures.
<P>
<PRE>
(define gen-counter
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) n))))
(let ((g (gen-counter)))
  (eqv? g g))               =>  #t
(eqv? (gen-counter) (gen-counter))
                            =>  #f
(define gen-loser
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) 27))))
(let ((g (gen-loser)))
  (eqv? g g))               =>  #t
(eqv? (gen-loser) (gen-loser))
                            =>  <EM>unspecified</EM>

(letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
         (g (lambda () (if (eqv? f g) 'both 'g)))
  (eqv? f g))
                            =>  <EM>unspecified</EM>

(letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
         (g (lambda () (if (eqv? f g) 'g 'both)))
  (eqv? f g))
                            =>  #f
</PRE>
<P>
Since it is an error to modify constant objects (those returned by
literal expressions), implementations are permitted, though not
required, to share structure between constants where appropriate.  Thus
the value of <CODE>eqv?</CODE> on constants is sometimes
<A NAME="IDX202"></A>
implementation-dependent.
<P>
<PRE>
(eqv? '(a) '(a))            =>  <EM>unspecified</EM>
(eqv? "a" "a")              =>  <EM>unspecified</EM>
(eqv? '(b) (cdr '(a b)))    =>  <EM>unspecified</EM>
(let ((x '(a)))
  (eqv? x x))               =>  #t
</PRE>
<P>
<EM>Rationale:</EM>  The above definition of <CODE>eqv?</CODE> allows implementations latitude in
<A NAME="IDX203"></A>
their treatment of procedures and literals:  implementations are free
either to detect or to fail to detect that two procedures or two literals
are equivalent to each other, and can decide whether or not to
merge representations of equivalent objects by using the same pointer or
bit pattern to represent both.
<P>
<A NAME="IDX204"></A>
<U>essential procedure:</U> <B>eq?</B> <I>obj1 obj2</I><P>
<P>
<CODE>Eq?</CODE> is similar to <CODE>eqv?</CODE> except that in some cases it
<A NAME="IDX205"></A>
is
<A NAME="IDX206"></A>
capable of discerning distinctions finer than those detectable by
<CODE>eqv?</CODE>.
<A NAME="IDX207"></A>
<P>
<CODE>Eq?</CODE> and <CODE>eqv?</CODE> are guaranteed to have the same
<A NAME="IDX209"></A>
<A NAME="IDX208"></A>
behavior on symbols, booleans, the empty list, pairs, and non-empty
strings and vectors.  <CODE>Eq?</CODE>'s behavior on numbers and characters is
<A NAME="IDX210"></A>
implementation-dependent, but it will always return either true or
false, and will return true only when <CODE>eqv?</CODE> would also return
<A NAME="IDX211"></A>
true.  <CODE>Eq?</CODE> may also behave differently from <CODE>eqv?</CODE> on
<A NAME="IDX212"></A>
empty
<A NAME="IDX213"></A>
vectors and empty strings.
<P>
<PRE>
(eq? 'a 'a)                 =>  #t
(eq? '(a) '(a))             =>  <EM>unspecified</EM>
(eq? (list 'a) (list 'a))   =>  #f
(eq? "a" "a")               =>  <EM>unspecified</EM>
(eq? "" "")                 =>  <EM>unspecified</EM>
(eq? '() '())               =>  #t
(eq? 2 2)                   =>  <EM>unspecified</EM>
(eq? #\A #\A)               =>  <EM>unspecified</EM>
(eq? car car)               =>  #t
(let ((n (+ 2 3)))
  (eq? n n))                =>  <EM>unspecified</EM>
(let ((x '(a)))
  (eq? x x))                =>  #t
(let ((x '#()))
  (eq? x x))                =>  #t
(let ((p (lambda (x) x)))
  (eq? p p))                =>  #t
</PRE>
<P>
<EM>Rationale:</EM>  It will usually be possible to implement <CODE>eq?</CODE>
much
<A NAME="IDX214"></A>
more efficiently than <CODE>eqv?</CODE>, for example, as a simple pointer
<A NAME="IDX215"></A>
comparison instead of as some more complicated operation.  One reason is
that it may not be possible to compute <CODE>eqv?</CODE> of two numbers in
<A NAME="IDX216"></A>
constant time, whereas <CODE>eq?</CODE> implemented as pointer comparison
will
<A NAME="IDX217"></A>
always finish in constant time.  <CODE>Eq?</CODE> may be used like <CODE>eqv?</CODE>
<A NAME="IDX218"></A>
in applications using procedures to implement objects with state since
it obeys the same constraints as <CODE>eqv?</CODE>.
<A NAME="IDX219"></A>
<P>
<A NAME="IDX220"></A>
<U>essential procedure:</U> <B>equal?</B> <I>obj1 obj2</I><P>
<P>
<CODE>Equal?</CODE> recursively compares the contents of pairs, vectors, and
<A NAME="IDX221"></A>
strings, applying <CODE>eqv?</CODE> on other objects such as numbers and
symbols.
<A NAME="IDX222"></A>
A rule of thumb is that objects are generally <CODE>equal?</CODE> if they
print
<A NAME="IDX223"></A>
the same.  <CODE>Equal?</CODE> may fail to terminate if its arguments are
<A NAME="IDX224"></A>
circular data structures.
<P>
<PRE>
(equal? 'a 'a)              =>  #t
(equal? '(a) '(a))          =>  #t
(equal? '(a (b) c)
        '(a (b) c))         =>  #t
(equal? "abc" "abc")        =>  #t
(equal? 2 2)                =>  #t
(equal? (make-vector 5 'a)
        (make-vector 5 'a)) =>  #t
(equal? (lambda (x) x)
        (lambda (y) y))     =>  <EM>unspecified</EM>
</PRE>
<P>
<H2><A NAME="SEC48" HREF="r4rs_toc.htm#SEC48">Pairs and lists</A></H2>
<P>
A <DFN>pair</DFN> (sometimes called a <DFN>dotted pair</DFN>) is a
record structure with two fields called the car and cdr fields (for
historical reasons).  Pairs are created by the procedure <CODE>cons</CODE>.
<A NAME="IDX225"></A>
The car and cdr fields are accessed by the procedures <CODE>car</CODE> and
<A NAME="IDX226"></A>
<CODE>cdr</CODE>.  The car and cdr fields are assigned by the procedures
<A NAME="IDX227"></A>
<CODE>set-car!</CODE> and <CODE>set-cdr!</CODE>.
<A NAME="IDX229"></A>
<A NAME="IDX228"></A>
<P>
Pairs are used primarily to represent lists.  A list can be defined
recursively as either the empty list
<A NAME="IDX230"></A>
or a pair whose cdr is a list.  More precisely, the set of lists is
defined as the smallest set <VAR>X</VAR> such that
<P>
<UL>
<LI>The empty list is in <VAR>X</VAR>.
<LI>If <VAR>list</VAR> is in <VAR>X</VAR>, then any pair whose cdr field contains
      <VAR>list</VAR> is also in <VAR>X</VAR>.
</UL>
<P>
The objects in the car fields of successive pairs of a list are the
elements of the list.  For example, a two-element list is a pair whose car
is the first element and whose cdr is a pair whose car is the second element
and whose cdr is the empty list.  The length of a list is the number of
elements, which is the same as the number of pairs.
<P>
The empty list
<A NAME="IDX231"></A>
is a special object of its own type (it is not a pair); it has no
elements and its length is zero.
<P>
<EM>Note:</EM>  The above definitions imply that all lists have finite length and are
terminated by the empty list.
<P>
The most general notation (external representation) for Scheme pairs is
the "dotted" notation <CODE>(<VAR>c1</VAR> . <VAR>c2</VAR>)</CODE> where
<VAR>c1</VAR> is the value of the car field and <VAR>c2</VAR> is the value of the
cdr field.  For example <CODE>(4 . 5)</CODE> is a pair whose car is 4
and whose cdr is 5.  Note that <CODE>(4 . 5)</CODE> is the external
representation of a pair, not an expression that evaluates to a pair.
<P>
A more streamlined notation can be used for lists: the elements of the
list are simply enclosed in parentheses and separated by spaces.  The
empty list
<A NAME="IDX232"></A>
is written <CODE>()</CODE>.  For example,
<P>
<PRE>
(a b c d e)
</PRE>
<P>
and
<P>
<PRE>
(a . (b . (c . (d . (e . ())))))
</PRE>
<P>
are equivalent notations for a list of symbols.
<P>
A chain of pairs not ending in the empty list is called an
<DFN>improper list</DFN>.  Note that an improper list is not a list.
The list and dotted notations can be combined to represent
improper lists:
<P>
<PRE>
(a b c . d)
</PRE>
<P>
is equivalent to
<P>
<PRE>
(a . (b . (c . d)))
</PRE>
<P>
Whether a given pair is a list depends upon what is stored in the cdr
field.  When the <CODE>set-cdr!</CODE> procedure is used, an object can be a
<A NAME="IDX233"></A>
list one moment and not the next:
<P>
<PRE>
(define x (list 'a 'b 'c))
(define y x)
y                           =>  (a b c)
(list? y)                   =>  #t
(set-cdr! x 4)              =>  <EM>unspecified</EM>
x                           =>  (a . 4)
(eqv? x y)                  =>  #t
y                           =>  (a . 4)
(list? y)                   =>  #f
(set-cdr! x x)              =>  <EM>unspecified</EM>
(list? x)                   =>  #f
</PRE>
<P>
Within literal expressions and representations of objects read by the
<CODE>read</CODE> procedure, the forms <CODE>'&#60;datum&#62;</CODE>,<CODE>`&#60;datum&#62;</CODE>,
<CODE>,&#60;datum&#62;</CODE>, and <CODE>,@&#60;datum&#62;</CODE> denote two-element lists
<A NAME="IDX235"></A>
<A NAME="IDX236"></A>
<A NAME="IDX237"></A>
<A NAME="IDX234"></A>
whose first elements are the symbols <CODE>quote</CODE>, <CODE>quasiquote</CODE>,
<CODE>unquote</CODE>, and
<A NAME="IDX239"></A>
<A NAME="IDX240"></A>
<A NAME="IDX241"></A>
<A NAME="IDX238"></A>
<CODE>unquote-splicing</CODE>, respectively.  The second element in each case
is &#60;datum&#62;.  This convention is supported so that arbitrary Scheme
programs may be represented as lists.
That is, according to Scheme's grammar, every
&#60;expression&#62; is also a &#60;datum&#62; (see section <A HREF="r4rs_5.htm#SEC22">External representations</A>).
Among other things, this permits the use of the <CODE>read</CODE> procedure to
<A NAME="IDX242"></A>
parse Scheme programs.  See section <A HREF="r4rs_5.htm#SEC22">External representations</A>.
<P>
<A NAME="IDX243"></A>
<U>essential procedure:</U> <B>pair?</B> <I>obj</I><P>
<P>
<CODE>Pair?</CODE> returns <CODE>#t</CODE> if <VAR>obj</VAR> is a pair, and otherwise
<A NAME="IDX244"></A>
returns <CODE>#f</CODE>.
<P>
<PRE>
(pair? '(a . b))            =>  #t
(pair? '(a b c))            =>  #t
(pair? '())                 =>  #f
(pair? '#(a b))             =>  #f
</PRE>
<P>
<A NAME="IDX245"></A>
<U>essential procedure:</U> <B>cons</B> <I>obj1 obj2</I><P>
<P>
Returns a newly allocated pair whose car is <VAR>obj1</VAR> and whose cdr is
<VAR>obj2</VAR>.  The pair is guaranteed to be different (in the sense of
<CODE>eqv?</CODE>) from every existing object.
<A NAME="IDX246"></A>
<P>
<PRE>
(cons 'a '())               =>  (a)
(cons '(a) '(b c d))        =>  ((a) b c d)
(cons "a" '(b c))           =>  ("a" b c)
(cons 'a 3)                 =>  (a . 3)
(cons '(a b) 'c)            =>  ((a b) . c)
</PRE>
<P>
<A NAME="IDX247"></A>
<U>essential procedure:</U> <B>car</B> <I>pair</I><P>
<P>
Returns the contents of the car field of <VAR>pair</VAR>.  Note that it is an
error to take the car of the empty list.
<A NAME="IDX248"></A>
<P>
<PRE>
(car '(a b c))              =>  a
(car '((a) b c d))          =>  (a)
(car '(1 . 2))              =>  1
(car '())                   =>  <EM>error</EM>
</PRE>
<P>
<A NAME="IDX249"></A>
<U>essential procedure:</U> <B>cdr</B> <I>pair</I><P>
<P>
Returns the contents of the cdr field of <VAR>pair</VAR>.
Note that it is an error to take the cdr of the empty list.
<P>
<PRE>
(cdr '((a) b c d))          =>  (b c d)
(cdr '(1 . 2))              =>  2
(cdr '())                   =>  <EM>error</EM>
</PRE>
<P>
<A NAME="IDX250"></A>
<U>essential procedure:</U> <B>set-car!</B> <I>pair obj</I><P>
<P>
Stores <VAR>obj</VAR> in the car field of <VAR>pair</VAR>.
The value returned by <CODE>set-car!</CODE> is unspecified.  
<A NAME="IDX251"></A>
<P>
<PRE>
(define (f) (list 'not-a-constant-list))
(define (g) '(constant-list))
(set-car! (f) 3)            =>  <EM>unspecified</EM>
(set-car! (g) 3)            =>  <EM>error</EM>
</PRE>
<P>
<A NAME="IDX252"></A>
<U>essential procedure:</U> <B>set-cdr!</B> <I>pair obj</I><P>
<P>
Stores <VAR>obj</VAR> in the cdr field of <VAR>pair</VAR>.
The value returned by <CODE>set-cdr!</CODE> is unspecified.  
<A NAME="IDX253"></A>
<P>
<A NAME="IDX254"></A>
<U>essential procedure:</U> <B>caar</B> <I>pair</I><P>
<A NAME="IDX255"></A>
<U>essential procedure:</U> <B>cadr</B> <I>pair</I><P>
...
<A NAME="IDX256"></A>
<U>essential procedure:</U> <B>cdddar</B> <I>pair</I><P>
<A NAME="IDX257"></A>
<U>essential procedure:</U> <B>cddddr</B> <I>pair</I><P>
<P>
These procedures are compositions of <CODE>car</CODE> and <CODE>cdr</CODE>, where
<A NAME="IDX259"></A>
<A NAME="IDX258"></A>
for example <CODE>caddr</CODE> could be defined by
<A NAME="IDX260"></A>
<P>
<PRE>
(define caddr (lambda (x) (car (cdr (cdr x))))).
</PRE>
<P>
Arbitrary compositions, up to four deep, are provided.  There are
twenty-eight of these procedures in all.
<P>
<A NAME="IDX261"></A>
<U>essential procedure:</U> <B>null?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is the empty list, otherwise returns
<CODE>#f</CODE>.
<A NAME="IDX262"></A>
<A NAME="IDX263"></A>
<P>
<A NAME="IDX264"></A>
<U>essential procedure:</U> <B>list?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a list, otherwise returns <CODE>#f</CODE>.
By definition, all lists have finite length and are terminated by
the empty list.
<P>
<PRE>
        (list? '(a b c))    =>  #t
        (list? '())         =>  #t
        (list? '(a . b))    =>  #f
        (let ((x (list 'a)))
          (set-cdr! x x)
          (list? x))        =>  #f
</PRE>
<P>
<A NAME="IDX265"></A>
<U>essential procedure:</U> <B>list</B> <I>obj ...</I><P>
<P>
Returns a newly allocated list of its arguments.
<P>
<PRE>
(list 'a (+ 3 4) 'c)        =>  (a 7 c)
(list)                      =>  ()
</PRE>
<P>
<A NAME="IDX266"></A>
<U>essential procedure:</U> <B>length</B> <I>list</I><P>
<P>
Returns the length of <VAR>list</VAR>.
<P>
<PRE>
(length '(a b c))           =>  3
(length '(a (b) (c d e)))   =>  3
(length '())                =>  0
</PRE>
<P>
<A NAME="IDX267"></A>
<U>essential procedure:</U> <B>append</B> <I>list ...</I><P>
<P>
Returns a list consisting of the elements of the first <VAR>list</VAR>
followed by the elements of the other <VAR>list</VAR>s.
<P>
<PRE>
(append '(x) '(y))          =>  (x y)
(append '(a) '(b c d))      =>  (a b c d)
(append '(a (b)) '((c)))    =>  (a (b) (c))
</PRE>
<P>
The resulting list is always newly allocated, except that it shares
structure with the last <VAR>list</VAR> argument.  The last argument may
actually be any object; an improper list results if the last argument is not a
proper list.
<P>
<PRE>
(append '(a b) '(c . d))    =>  (a b c . d)
(append '() 'a)             =>  a
</PRE>
<P>
<A NAME="IDX268"></A>
<U>essential procedure:</U> <B>reverse</B> <I>list</I><P>
<P>
Returns a newly allocated list consisting of the elements of <VAR>list</VAR>
in reverse order.
<P>
<PRE>
(reverse '(a b c))          =>  (c b a)
(reverse '(a (b c) d (e (f))))  
                            =>  ((e (f)) d (b c) a)
</PRE>
<P>
<A NAME="IDX269"></A>
<U>procedure:</U> <B>list-tail</B> <I>list k</I><P>
<P>
Returns the sublist of <VAR>list</VAR> obtained by omitting the first <VAR>k</VAR>
elements.
<CODE>List-tail</CODE> could be defined by
<A NAME="IDX270"></A>
<P>
<PRE>
(define list-tail
  (lambda (x k)
    (if (zero? k)
        x
        (list-tail (cdr x) (- k 1)))))
</PRE>
<P>
<A NAME="IDX271"></A>
<U>essential procedure:</U> <B>list-ref</B> <I>list k</I><P>
<P>
Returns the <VAR>k</VAR>th element of <VAR>list</VAR>.  (This is the same
as the car of <CODE>(list-tail <VAR>list</VAR> <VAR>k</VAR>)</CODE>.)
<P>
<PRE>
(list-ref '(a b c d) 2)     =>  c
(list-ref '(a b c d)
          (inexact-&#62;exact (round 1.8))) 
                            =>  c
</PRE>
<P>
<A NAME="IDX272"></A>
<U>essential procedure:</U> <B>memq</B> <I>obj list</I><P>
<A NAME="IDX273"></A>
<U>essential procedure:</U> <B>memv</B> <I>obj list</I><P>
<A NAME="IDX274"></A>
<U>essential procedure:</U> <B>member</B> <I>obj list</I><P>
<P>
These procedures return the first sublist of <VAR>list</VAR> whose car is
<VAR>obj</VAR>, where the sublists of <VAR>list</VAR> are the non-empty lists
returned by <CODE>(list-tail <VAR>list</VAR> <VAR>k</VAR>)</CODE> for <VAR>k</VAR> less
than the length of <VAR>list</VAR>.  If
<VAR>obj</VAR> does not occur in <VAR>list</VAR>, then <CODE>#f</CODE> (not the empty list) is
returned.  <CODE>Memq</CODE> uses <CODE>eq?</CODE> to compare <VAR>obj</VAR> with the
<A NAME="IDX275"></A>
elements of
<A NAME="IDX276"></A>
<VAR>list</VAR>, while <CODE>memv</CODE> uses <CODE>eqv?</CODE> and <CODE>member</CODE>
<A NAME="IDX278"></A>
<A NAME="IDX277"></A>
uses <CODE>equal?</CODE>.
<A NAME="IDX280"></A>
<A NAME="IDX279"></A>
<P>
<PRE>
(memq 'a '(a b c))          =>  (a b c)
(memq 'b '(a b c))          =>  (b c)
(memq 'a '(b c d))          =>  #f
(memq (list 'a) '(b (a) c)) =>  #f
(member (list 'a)
        '(b (a) c))         =>  ((a) c)
(memq 101 '(100 101 102))   =>  <EM>unspecified</EM>
(memv 101 '(100 101 102))   =>  (101 102)
</PRE>
<P>
<A NAME="IDX281"></A>
<U>essential procedure:</U> <B>assq</B> <I>obj alist</I><P>
<A NAME="IDX282"></A>
<U>essential procedure:</U> <B>assv</B> <I>obj alist</I><P>
<A NAME="IDX283"></A>
<U>essential procedure:</U> <B>assoc</B> <I>obj alist</I><P>
<P>
<VAR>Alist</VAR> (for "association list") must be a list of pairs.  These
procedures find the first pair in <VAR>alist</VAR> whose car field is
<VAR>obj</VAR>, and returns that pair.  If no pair in <VAR>alist</VAR> has
<VAR>obj</VAR> as its car, then <CODE>#f</CODE> (not the empty list) is returned.
<CODE>Assq</CODE> uses <CODE>eq?</CODE> to compare <VAR>obj</VAR> with the car fields of
the pairs in <VAR>alist</VAR>, while <CODE>assv</CODE> uses <CODE>eqv?</CODE> and
<CODE>assoc</CODE> uses <CODE>equal?</CODE>.
<A NAME="IDX285"></A>
<A NAME="IDX286"></A>
<A NAME="IDX287"></A>
<A NAME="IDX288"></A>
<A NAME="IDX289"></A>
<A NAME="IDX284"></A>
<P>
<PRE>
(define e '((a 1) (b 2) (c 3)))
(assq 'a e)                 =>  (a 1)
(assq 'b e)                 =>  (b 2)
(assq 'd e)                 =>  #f
(assq (list 'a) '(((a)) ((b)) ((c))))
                            =>  #f
(assoc (list 'a) '(((a)) ((b)) ((c))))
                            =>  ((a))
(assq 5 '((2 3) (5 7) (11 13)))
                            =>  <EM>unspecified</EM>
(assv 5 '((2 3) (5 7) (11 13)))
                            =>  (5 7)
</PRE>
<P>
<EM>Rationale:</EM>  Although they are ordinarily used as predicates,
<CODE>memq</CODE>, <CODE>memv</CODE>, <CODE>member</CODE>, <CODE>assq</CODE>, <CODE>assv</CODE>, and
symbols<CODE>assoc</CODE> do not
<A NAME="IDX291"></A>
<A NAME="IDX292"></A>
<A NAME="IDX293"></A>
<A NAME="IDX294"></A>
<A NAME="IDX295"></A>
<A NAME="IDX290"></A>
have question marks in their names because they return useful values
rather than just <CODE>#t</CODE> or <CODE>#f</CODE>.
<P>
<H2><A NAME="SEC49" HREF="r4rs_toc.htm#SEC49">Symbols</A></H2>
<P>
Symbols are objects whose usefulness rests on the fact that two symbols
are identical (in the sense of <CODE>eqv?</CODE>) if and only if their
<A NAME="IDX296"></A>
names are spelled the same way.  This is exactly the property needed to
represent identifiers
<A NAME="IDX297"></A>
in programs, and so most implementations of Scheme use them internally
for that purpose.  Symbols are useful for many other applications; for
instance, they may be used the way enumerated values are used in Pascal.
<P>
The rules for writing a symbol are exactly the same as the rules for
writing an identifier; see section <A HREF="r4rs_4.htm#SEC16">Identifiers</A>
and section <A HREF="r4rs_9.htm#SEC68">Lexical structure</A>.
<P>
It is guaranteed that any symbol that has been returned as part of
a literal expression, or read using the <CODE>read</CODE> procedure, and
<A NAME="IDX298"></A>
subsequently written out using the <CODE>write</CODE> procedure, will read
back
<A NAME="IDX299"></A>
in as the identical symbol (in the sense of <CODE>eqv?</CODE>).  The
<A NAME="IDX300"></A>
<CODE>string-&#62;symbol</CODE> procedure, however, can create symbols for
<A NAME="IDX301"></A>
which this write/read invariance may not hold because their names
contain special characters or letters in the non-standard case.
<P>
<EM>Note:</EM>  Some implementations of Scheme have a feature known as "slashification"
in order to guarantee write/read invariance for all symbols, but
historically the most important use of this feature has been to
compensate for the lack of a string data type.
<P>
Some implementations also have "uninterned symbols", which
defeat write/read invariance even in implementations with slashification,
and also generate exceptions to the rule that two symbols are the same
if and only if their names are spelled the same.
<P>
<A NAME="IDX302"></A>
<U>essential procedure:</U> <B>symbol?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a symbol, otherwise returns <CODE>#f</CODE>.
<P>
<PRE>
(symbol? 'foo)              =>  #t
(symbol? (car '(a b)))      =>  #t
(symbol? "bar")             =>  #f
(symbol? 'nil)              =>  #t
(symbol? '())               =>  #f
(symbol? #f)                =>  #f
</PRE>
<P>
<A NAME="IDX303"></A>
<U>essential procedure:</U> <B>symbol-&#62;string</B> <I>symbol</I><P>
<P>
Returns the name of <VAR>symbol</VAR> as a string.  If the symbol was part of
an object returned as the value of a literal expression
(section <A HREF="r4rs_6.htm#SEC28">Literal expressions</A>) or by a call to the <CODE>read</CODE>
<A NAME="IDX304"></A>
procedure,
and its name contains alphabetic characters, then the string returned
will contain characters in the implementation's preferred standard
case--some implementations will prefer upper case, others lower case.
If the symbol was returned by <CODE>string-&#62;symbol</CODE>, the case of
<A NAME="IDX305"></A>
characters in the string returned will be the same as the case in the
string that was passed to <CODE>string-&#62;symbol</CODE>.  It is an error
<A NAME="IDX306"></A>
to apply mutation procedures like <CODE>string-set!</CODE> to strings returned
<A NAME="IDX307"></A>
by this procedure.
<P>
The following examples assume that the implementation's standard case is
lower case:
<P>
<PRE>
(symbol-&#62;string 'flying-fish)
                            =>  "flying-fish"
(symbol-&#62;string 'Martin)    =>  "martin"
(symbol-&#62;string
   (string-&#62;symbol "Malvina"))
                            =>  "Malvina"
</PRE>
<P>
<A NAME="IDX308"></A>
<U>essential procedure:</U> <B>string-&#62;symbol</B> <I>string</I><P>
<P>
Returns the symbol whose name is <VAR>string</VAR>.  This procedure can
create symbols with names containing special characters or letters in
the non-standard case, but it is usually a bad idea to create such
symbols because in some implementations of Scheme they cannot be read as
themselves.  See <CODE>symbol-&#62;string</CODE>.
<A NAME="IDX309"></A>
<P>
The following examples assume that the implementation's standard case is
lower case:
<P>
<PRE>
(eq? 'mISSISSIppi 'mississippi)  
                            =>  #t
(string-&#62;symbol "mISSISSIppi")  
                            =>  the symbol with name "mISSISSIppi"
(eq? 'bitBlt (string-&#62;symbol "bitBlt"))     
                            =>  #f
(eq? 'JollyWog
     (string-&#62;symbol
       (symbol-&#62;string 'JollyWog)))  
                            =>  #t
(string=? "K. Harper, M.D."
          (symbol-&#62;string
            (string-&#62;symbol "K. Harper, M.D.")))  
                            =>  #t
</PRE>
<P>
<H2><A NAME="SEC50" HREF="r4rs_toc.htm#SEC50">Numbers</A></H2>
<A NAME="IDX310"></A>
<P>
Numerical computation has traditionally been neglected by the Lisp
community.  Until Common Lisp there was no carefully thought out
strategy for organizing numerical computation, and with the exception of
the MacLisp system [PITMAN83] little effort was made to
execute numerical code efficiently.  This report recognizes the excellent work
of the Common Lisp committee and accepts many of their recommendations.
In some ways this report simplifies and generalizes their proposals in a manner
consistent with the purposes of Scheme.
<P>
It is important to distinguish between the mathematical numbers, the
Scheme numbers that attempt to model them, the machine representations
used to implement the Scheme numbers, and notations used to write numbers.
This report uses the types <I>number</I>, <I>complex</I>, <I>real</I>,
<I>rational</I>, and <I>integer</I> to refer to both mathematical numbers
and Scheme numbers.  Machine representations such as fixed point and
floating point are referred to by names such as <I>fixnum</I> and
<I>flonum</I>.
<P>
<H3><A NAME="SEC51" HREF="r4rs_toc.htm#SEC51">Numerical types</A></H3>
<A NAME="IDX311"></A>
<P>
Mathematically, numbers may be arranged into a tower of subtypes
in which each level is a subset of the level above it:
<UL>
<LI>number
<LI>complex
<LI>real
<LI>rational
<LI>integer
</UL>
<P>
For example, 3 is an integer.  Therefore 3 is also a rational,
a real, and a complex.  The same is true of the Scheme numbers
that model 3.  For Scheme numbers, these types are defined by the
predicates <CODE>number?</CODE>, <CODE>complex?</CODE>, <CODE>real?</CODE>,
<CODE>rational?</CODE>, and <CODE>integer?</CODE>.
<A NAME="IDX313"></A>
<A NAME="IDX314"></A>
<A NAME="IDX315"></A>
<A NAME="IDX316"></A>
<A NAME="IDX312"></A>
<P>
There is no simple relationship between a number's type and its
representation inside a computer.  Although most implementations of
Scheme will offer at least two different representations of 3, these
different representations denote the same integer.
<P>
Scheme's numerical operations treat numbers as abstract data, as
independent of their representation as possible.  Although an implementation
of Scheme may use fixnum, flonum, and perhaps other representations for
numbers, this should not be apparent to a casual programmer writing
simple programs.
<P>
It is necessary, however, to distinguish between numbers that are
represented exactly and those that may not be.  For example, indexes
into data structures must be known exactly, as must some polynomial
coefficients in a symbolic algebra system.  On the other hand, the
results of measurements are inherently inexact, and irrational numbers
may be approximated by rational and therefore inexact approximations.
In order to catch uses of inexact numbers where exact numbers are
required, Scheme explicitly distinguishes exact from inexact numbers.
This distinction is orthogonal to the dimension of type.
<P>
<H3><A NAME="SEC52" HREF="r4rs_toc.htm#SEC52">Exactness</A></H3>
<P>
<A NAME="IDX317"></A>
<P>
Scheme numbers are either <I>exact</I> or <I>inexact</I>.  A number is
exact if it was written as an exact constant or was derived from
exact numbers using only exact operations.  A number is
inexact if it was written as an inexact constant,
if it was
derived using inexact ingredients, or if it was derived using
inexact operations. Thus inexactness is a contagious
property of a number.
<P>
If two implementations produce exact results for a
computation that did not involve inexact intermediate results,
the two ultimate results will be mathematically equivalent.  This is
generally not true of computations involving inexact numbers
since approximate methods such as floating point arithmetic may be used,
but it is the duty of each implementation to make the result as close as
practical to the mathematically ideal result.
<P>
Rational operations such as <CODE>+</CODE> should always produce
<A NAME="IDX318"></A>
exact results when given exact arguments.
If the operation is unable to produce an exact result,
then it may either report the violation of an implementation restriction
or it may silently coerce its
result to an inexact value.
See section <A HREF="r4rs_8.htm#SEC53">Implementation restrictions</A>.
<P>
With the exception of <CODE>inexact-&#62;exact</CODE>, the operations described in
<A NAME="IDX319"></A>
this section must generally return inexact results when given any inexact
arguments.  An operation may, however, return an exact result if it can
prove that the value of the result is unaffected by the inexactness of its
arguments.  For example, multiplication of any number by an exact zero
may produce an exact zero result, even if the other argument is
inexact.
<P>
<H3><A NAME="SEC53" HREF="r4rs_toc.htm#SEC53">Implementation restrictions</A></H3>
<A NAME="IDX320"></A>
<P>
Implementations of Scheme are not required to implement the whole
tower of subtypes given in section <A HREF="r4rs_8.htm#SEC51">Numerical types</A>,
but they must implement a coherent subset consistent with both the
purposes of the implementation and the spirit of the Scheme language.
For example, an implementation in which all numbers are real
may still be quite useful.
<P>
Implementations may also support only a limited range of numbers of
any type, subject to the requirements of this section.  The supported
range for exact numbers of any type may be different from the
supported range for inexact numbers of that type.  For example,
an implementation that uses flonums to represent all its
inexact real numbers may
support a practically unbounded range of exact integers
and rationals
while limiting the range of inexact reals (and therefore
the range of inexact integers and rationals)
to the dynamic range of the flonum format.
Furthermore
the gaps between the representable inexact integers and
rationals are
likely to be very large in such an implementation as the limits of this
range are approached.
<P>
An implementation of Scheme must support exact integers
throughout the range of numbers that may be used for indexes of
lists, vectors, and strings or that may result from computing the length of a
list, vector, or string.  The <CODE>length</CODE>, <CODE>vector-length</CODE>,
<A NAME="IDX322"></A>
<A NAME="IDX321"></A>
and <CODE>string-length</CODE> procedures must return an exact
<A NAME="IDX323"></A>
integer, and it is an error to use anything but an exact integer as an
index.  Furthermore any integer constant within the index range, if
expressed by an exact integer syntax, will indeed be read as an exact
integer, regardless of any implementation restrictions that may apply
outside this range.  Finally, the procedures listed below will always
return an exact integer result provided all their arguments are exact integers
and the mathematically expected result is representable as an exact integer
within the implementation:
<P>
<PRE>
+            -             *
quotient     remainder     modulo
max          min           abs
numerator    denominator   gcd
lcm          floor         ceiling
truncate     round         rationalize
expt
</PRE>
<P>
Implementations are encouraged, but not required, to support
exact integers and exact rationals of
practically unlimited size and precision, and to implement the
above procedures and the <CODE>/</CODE> procedure in
<A NAME="IDX324"></A>
such a way that they always return exact results when given exact
arguments.  If one of these procedures is unable to deliver an exact
result when given exact arguments, then it may either report a
violation of an
implementation restriction or it may silently coerce its result to an
inexact number.  Such a coercion may cause an error later.
<P>
<A NAME="IDX325"></A>
<A NAME="IDX326"></A>
<P>
An implementation may use floating point and other approximate
representation strategies for inexact numbers.
<P>
This report recommends, but does not require, that the IEEE 32-bit
and 64-bit floating point standards be followed by implementations that use
flonum representations, and that implementations using
other representations should match or exceed the precision achievable
using these floating point standards <A HREF="r4rs_13.htm#BIB49">[IEEE]</A>.
<P>
In particular, implementations that use flonum representations
must follow these rules: A flonum result
must be represented with at least as much precision as is used to express any of
the inexact arguments to that operation.  It is desirable (but not required) for
potentially inexact operations such as <CODE>sqrt</CODE>, when applied to
exact
<A NAME="IDX327"></A>
arguments, to produce exact answers whenever possible (for example the
square root of an exact 4 ought to be an exact 2).
If, however, an
exact number is operated upon so as to produce an inexact result
(as by <CODE>sqrt</CODE>), and if the result is represented as a
flonum, then
<A NAME="IDX328"></A>
the most precise flonum format available must be used; but if the result
is represented in some other way then the representation must have at least as
much precision as the most precise flonum format available.
<P>
Although Scheme allows a variety of written
notations for
numbers, any particular implementation may support only some of them.
For example, an implementation in which all numbers are real
need not support the rectangular and polar notations for complex
numbers.  If an implementation encounters an exact numerical constant that
it cannot represent as an exact number, then it may either report a
violation of an implementation restriction or it may silently represent the
constant by an inexact number.
<P>
<H3><A NAME="SEC54" HREF="r4rs_toc.htm#SEC54">Syntax of numerical constants</A></H3>
<P>
The syntax of the written representations for numbers is described formally in
section <A HREF="r4rs_9.htm#SEC68">Lexical structure</A>.
<P>
A number may be written in binary, octal, decimal, or
hexadecimal by the use of a radix prefix.  The radix prefixes are
<CODE>#b</CODE> (binary),
<A NAME="IDX329"></A>
<CODE>#o</CODE> (octal),
<A NAME="IDX330"></A>
<CODE>#d</CODE> (decimal), and
<A NAME="IDX331"></A>
<CODE>#x</CODE> (hexadecimal).
<A NAME="IDX332"></A>
With no radix prefix, a number is assumed to be expressed in decimal.
<P>
A
numerical constant may be specified to be either exact or
inexact by a prefix.  The prefixes are <CODE>#e</CODE>
<A NAME="IDX333"></A>
for exact, and <CODE>#i</CODE>
<A NAME="IDX334"></A>
for inexact.  An exactness
prefix may appear before or after any radix prefix that is used.  If
the written representation of a number has no exactness prefix, the
constant may be either inexact or exact.  It is
inexact if it contains a decimal point, an
exponent, or a "#" character in the place of a digit,
otherwise it is exact.
<P>
In systems with inexact numbers
of varying precisions it may be useful to specify
the precision of a constant.  For this purpose, numerical constants
may be written with an exponent marker that indicates the
desired precision of the inexact
representation.  The letters <CODE>s</CODE>, <CODE>f</CODE>,
<A NAME="IDX336"></A>
<A NAME="IDX335"></A>
<CODE>d</CODE>, and <CODE>l</CODE> specify the use of <VAR>short</VAR>, <VAR>single</VAR>,
<A NAME="IDX338"></A>
<A NAME="IDX337"></A>
<VAR>double</VAR>, and <VAR>long</VAR> precision, respectively.  (When fewer
than four internal
inexact
representations exist, the four size
specifications are mapped onto those available.  For example, an
implementation with two internal representations may map short and
single together and long and double together.)  In addition, the
exponent marker <CODE>e</CODE> specifies the default precision for the
<A NAME="IDX339"></A>
implementation.  The default precision has at least as much precision
as <VAR>double</VAR>, but
implementations may wish to allow this default to be set by the user.
<P>
<PRE>
3.14159265358979F0
        Round to single --- 3.141593
0.6L0
        Extend to long --- .600000000000000
</PRE>
<P>
<H3><A NAME="SEC55" HREF="r4rs_toc.htm#SEC55">Numerical operations</A></H3>
<P>
The reader is referred to section <A HREF="r4rs_3.htm#SEC12">Entry format</A> for a summary
of the naming conventions used to specify restrictions on the types of
arguments to numerical routines.
<P>
The examples used in this section assume that any numerical constant written
using an exact notation is indeed represented as an exact
number.  Some examples also assume that certain numerical constants written
using an inexact notation can be represented without loss of
accuracy; the inexact constants were chosen so that this is
likely to be true in implementations that use flonums to represent
inexact numbers.
<P>
<A NAME="IDX340"></A>
<U>essential procedure:</U> <B>number?</B> <I>obj</I><P>
<A NAME="IDX341"></A>
<U>essential procedure:</U> <B>complex?</B> <I>obj</I><P>
<A NAME="IDX342"></A>
<U>essential procedure:</U> <B>real?</B> <I>obj</I><P>
<A NAME="IDX343"></A>
<U>essential procedure:</U> <B>rational?</B> <I>obj</I><P>
<A NAME="IDX344"></A>
<U>essential procedure:</U> <B>integer?</B> <I>obj</I><P>
<P>
These numerical type predicates can be applied to any kind of
argument, including non-numbers.  They return <CODE>#t</CODE> if the object is
of the named type, and otherwise they return <CODE>#f</CODE>.
In general, if a type predicate is true of a number then all higher
type predicates are also true of that number.  Consequently, if a type
predicate is false of a number, then all lower type predicates are
also false of that number.
<P>
If <VAR>z</VAR> is an inexact complex number, then <CODE>(real? <VAR>z</VAR>)</CODE> is true if
and only if <CODE>(zero? (imag-part <VAR>z</VAR>))</CODE> is true.  If <VAR>x</VAR> is an inexact
real number, then <CODE>(integer? <VAR>x</VAR>)</CODE> is true if and only if
<CODE>(= <VAR>x</VAR> (round <VAR>x</VAR>))</CODE>.
<P>
<PRE>
(complex? 3+4i)             =>  #t
(complex? 3)                =>  #t
(real? 3)                   =>  #t
(real? -2.5+0.0i)           =>  #t
(real? #e1e10)              =>  #t
(rational? 6/10)            =>  #t
(rational? 6/3)             =>  #t
(integer? 3+0i)             =>  #t
(integer? 3.0)              =>  #t
(integer? 8/4)              =>  #t
</PRE>
<P>
<EM>Note:</EM>  The behavior of these type predicates on inexact numbers
is unreliable, since any inaccuracy may affect the result.
<P>
<EM>Note:</EM>  In many implementations the <CODE>rational?</CODE> procedure will be the same
<A NAME="IDX345"></A>
as <CODE>real?</CODE>, and the <CODE>complex?</CODE> procedure will be the same
<A NAME="IDX346"></A>
as
<A NAME="IDX347"></A>
<CODE>number?</CODE>, but unusual implementations may be able to represent
<A NAME="IDX348"></A>
some irrational numbers exactly or may extend the number system to
support some kind of non-complex numbers.
<P>
<A NAME="IDX349"></A>
<U>essential procedure:</U> <B>exact?</B> <I>z</I><P>
<A NAME="IDX350"></A>
<U>essential procedure:</U> <B>inexact?</B> <I>z</I><P>
<P>
These numerical predicates provide tests for the exactness of a
quantity.  For any Scheme number, precisely one of these predicates
is true.
<P>
<A NAME="IDX351"></A>
<U>essential procedure:</U> <B>=</B> <I>z1 z2 z3 ...</I><P>
<A NAME="IDX352"></A>
<U>essential procedure:</U> <B>&#60;</B> <I>x1 x2 x3 ...</I><P>
<A NAME="IDX353"></A>
<U>essential procedure:</U> <B>&#62;</B> <I>x1 x2 x3 ...</I><P>
<A NAME="IDX354"></A>
<U>essential procedure:</U> <B>&#60;=</B> <I>x1 x2 x3 ...</I><P>
<A NAME="IDX355"></A>
<U>essential procedure:</U> <B>&#62;=</B> <I>x1 x2 x3 ...</I><P>
<P>
These procedures return <CODE>#t</CODE> if their arguments are (respectively):
equal, monotonically increasing, monotonically decreasing,
monotonically nondecreasing, or monotonically nonincreasing.
<P>
These predicates are required to be transitive.
<P>
<EM>Note:</EM>  The traditional implementations of these predicates in Lisp-like
languages are not transitive.
<P>
<EM>Note:</EM>  While it is not an error to compare inexact numbers using these
predicates, the results may be unreliable because a small inaccuracy
may affect the result; this is especially true of <CODE>=</CODE> and <CODE>zero?</CODE>.
<A NAME="IDX357"></A>
<A NAME="IDX356"></A>
When in doubt, consult a numerical analyst.
<P>
<A NAME="IDX358"></A>
<U>essential procedure:</U> <B>zero?</B> <I>z</I><P>
<A NAME="IDX359"></A>
<U>essential procedure:</U> <B>positive?</B> <I>x</I><P>
<A NAME="IDX360"></A>
<U>essential procedure:</U> <B>negative?</B> <I>x</I><P>
<A NAME="IDX361"></A>
<U>essential procedure:</U> <B>odd?</B> <I>n</I><P>
<A NAME="IDX362"></A>
<U>essential procedure:</U> <B>even?</B> <I>n</I><P>
<P>
These numerical predicates test a number for a particular property,
returning <CODE>#t</CODE> or <CODE>#f</CODE>.  See note above.
<P>
<A NAME="IDX363"></A>
<U>essential procedure:</U> <B>max</B> <I>x1 x2 ...</I><P>
<A NAME="IDX364"></A>
<U>essential procedure:</U> <B>min</B> <I>x1 x2 ...</I><P>
<P>
These procedures return the maximum or minimum of their arguments.
<P>
<PRE>
(max 3 4)                   =>  4    ; exact
(max 3.9 4)                 =>  4.0  ; inexact
</PRE>
<P>
<EM>Note:</EM>  If any argument is inexact, then the result will also be inexact (unless
the procedure can prove that the inaccuracy is not large enough to affect the
result, which is possible only in unusual implementations).  If
<CODE>min</CODE> or
<A NAME="IDX365"></A>
<CODE>max</CODE> is used to compare numbers of mixed exactness, and the
numerical
<A NAME="IDX366"></A>
value of the result cannot be represented as an inexact number without loss of
accuracy, then the procedure may report a violation of an implementation
restriction.
<P>
<A NAME="IDX367"></A>
<U>essential procedure:</U> <B>+</B> <I>z1 ...</I><P>
<A NAME="IDX368"></A>
<U>essential procedure:</U> <B>*</B> <I>z1 ...</I><P>
<P>
These procedures return the sum or product of their arguments.
<P>
<PRE>
(+ 3 4)                     =>  7
(+ 3)                       =>  3
(+)                         =>  0
(* 4)                       =>  4
(*)                         =>  1
</PRE>
<P>
<A NAME="IDX369"></A>
<U>essential procedure:</U> <B>-</B> <I>z1 z2</I><P>
<A NAME="IDX370"></A>
<U>essential procedure:</U> <B>-</B> <I>z</I><P>
<A NAME="IDX371"></A>
<U>procedure:</U> <B>-</B> <I>z1 z2 ...</I><P>
<A NAME="IDX372"></A>
<U>essential procedure:</U> <B>/</B> <I>z1 z2</I><P>
<A NAME="IDX373"></A>
<U>essential procedure:</U> <B>/</B> <I>z</I><P>
<A NAME="IDX374"></A>
<U>procedure:</U> <B>/</B> <I>z1 z2 ...</I><P>
<P>
With two or more arguments, these procedures return the difference or
quotient of their arguments, associating to the left.  With one argument,
however, they return the additive or multiplicative inverse of their argument.
<P>
<PRE>
(- 3 4)                     =>  -1
(- 3 4 5)                   =>  -6
(- 3)                       =>  -3
(/ 3 4 5)                   =>  3/20
(/ 3)                       =>  1/3
</PRE>
<P>
<A NAME="IDX375"></A>
<U>essential procedure:</U> <B>abs</B> <I>x</I><P>
<P>
<CODE>Abs</CODE> returns the magnitude of its argument.
<A NAME="IDX377"></A>
<A NAME="IDX376"></A>
<PRE>
(abs -7)                    =>  7
</PRE>
<P>
<A NAME="IDX378"></A>
<U>essential procedure:</U> <B>quotient</B> <I>n1 n2</I><P>
<A NAME="IDX379"></A>
<U>essential procedure:</U> <B>remainder</B> <I>n1 n2</I><P>
<A NAME="IDX380"></A>
<U>essential procedure:</U> <B>modulo</B> <I>n1 n2</I><P>
<P>
These
procedures implement number-theoretic (integer)
division: For positive integers <VAR>n1</VAR> and <VAR>n2</VAR>, if <VAR>n3</VAR> and
<VAR>n4</VAR> are integers such that 
<DL COMPACT>
<DT><CODE>(= n1 (+ (* n2 n3) n4))</CODE>,
<DD><DT><CODE>(&#60;= 0 n4)</CODE>, and
<DD><DT><CODE>(&#60; n4 n2)</CODE>.
<DD></DL>
Then
<PRE>
(quotient <VAR>n1</VAR> <VAR>n2</VAR>)            =>  <VAR>n3</VAR>
(remainder <VAR>n1</VAR> <VAR>n2</VAR>)           =>  <VAR>n4</VAR>
(modulo <VAR>n1</VAR> <VAR>n2</VAR>)              =>  <VAR>n4</VAR>
</PRE>
<P>
For integers <VAR>n1</VAR> and <VAR>n2</VAR> with <VAR>n2</VAR> not equal to 0,
<P>
<PRE>
(= <VAR>n1</VAR> (+ (* <VAR>n2</VAR> (quotient <VAR>n1</VAR> <VAR>n2</VAR>))
               (remainder <VAR>n1</VAR> <VAR>n2</VAR>)))
                            =>  #t
</PRE>
<P>
provided all numbers involved in that computation are exact.
<P>
The value returned by <CODE>quotient</CODE> always has the sign of the
<A NAME="IDX381"></A>
product of its arguments.  <CODE>Remainder</CODE> and <CODE>modulo</CODE> differ
<A NAME="IDX382"></A>
on negative
<A NAME="IDX383"></A>
arguments--the
<CODE>remainder</CODE> is either zero or has the sign of the dividend,
<A NAME="IDX384"></A>
while the <CODE>modulo</CODE>
<A NAME="IDX385"></A>
always has the sign of the divisor:
<P>
<PRE>
(modulo 13 4)               =>  1
(remainder 13 4)            =>  1

(modulo -13 4)              =>  3
(remainder -13 4)           =>  -1

(modulo 13 -4)              =>  -3
(remainder 13 -4)           =>  1

(modulo -13 -4)             =>  -1
(remainder -13 -4)          =>  -1

(remainder -13 -4.0)        =>  -1.0  ; inexact
</PRE>
<P>
<A NAME="IDX386"></A>
<U>essential procedure:</U> <B>gcd</B> <I>n1 ...</I><P>
<A NAME="IDX387"></A>
<U>essential procedure:</U> <B>lcm</B> <I>n1 ...</I><P>
<P>
These procedures return the greatest common divisor or least common
multiple of their arguments.  The result is always non-negative.
<P>
<PRE>
(gcd 32 -36)                =>  4
(gcd)                       =>  0
(lcm 32 -36)                =>  288
(lcm 32.0 -36)              =>  288.0  ; inexact
(lcm)                       =>  1
</PRE>
<P>
<A NAME="IDX388"></A>
<U>procedure:</U> <B>numerator</B> <I>q</I><P>
<A NAME="IDX389"></A>
<U>procedure:</U> <B>denominator</B> <I>q</I><P>
<P>
These procedures return the numerator or denominator of their
argument; the result is computed as if the argument was represented as
a fraction in lowest terms.  The denominator is always positive.  The
denominator of 0 is defined to be 1.
<P>
<PRE>
(numerator (/ 6 4))         =>  3
(denominator (/ 6 4))       =>  2
(denominator
  (exact-&#62;inexact (/ 6 4))) =>  2.0
</PRE>
<P>
<A NAME="IDX390"></A>
<U>essential procedure:</U> <B>floor</B> <I>x</I><P>
<A NAME="IDX391"></A>
<U>essential procedure:</U> <B>ceiling</B> <I>x</I><P>
<A NAME="IDX392"></A>
<U>essential procedure:</U> <B>truncate</B> <I>x</I><P>
<A NAME="IDX393"></A>
<U>essential procedure:</U> <B>round</B> <I>x</I><P>
<P>
These procedures return integers.
<CODE>Floor</CODE> returns the largest integer not larger than <VAR>x</VAR>.
<A NAME="IDX394"></A>
<CODE>Ceiling</CODE> returns the smallest integer not smaller than <VAR>x</VAR>.
<A NAME="IDX395"></A>
<CODE>Truncate</CODE> returns the integer closest to <VAR>x</VAR> whose absolute
<A NAME="IDX396"></A>
value is not larger than the absolute value of <VAR>x</VAR>.  <CODE>Round</CODE>
returns the
<A NAME="IDX397"></A>
closest integer to <VAR>x</VAR>, rounding to even when <VAR>x</VAR> is halfway between two
integers.
<P>
<EM>Rationale:</EM>  <CODE>Round</CODE> rounds to even for consistency with the default rounding
<A NAME="IDX398"></A>
mode specified by the IEEE floating point standard.
<P>
<EM>Note:</EM>  If the argument to one of these procedures is inexact, then the result
will also be inexact.  If an exact value is needed, the
result should be passed to the <CODE>inexact-&#62;exact</CODE> procedure.
<A NAME="IDX399"></A>
<P>
<PRE>
(floor -4.3)                =>  -5.0
(ceiling -4.3)              =>  -4.0
(truncate -4.3)             =>  -4.0
(round -4.3)                =>  -4.0

(floor 3.5)                 =>  3.0
(ceiling 3.5)               =>  4.0
(truncate 3.5)              =>  3.0
(round 3.5)                 =>  4.0  ; inexact

(round 7/2)                 =>  4    ; exact
(round 7)                   =>  7
</PRE>
<P>
<A NAME="IDX400"></A>
<U>procedure:</U> <B>rationalize</B> <I>x y</I><P>
<P>
<CODE>Rationalize</CODE> returns the <EM>simplest</EM> rational number
<A NAME="IDX401"></A>
differing from <VAR>x</VAR> by no more than <VAR>y</VAR>.  A rational number
<VAR>r1</VAR> is <EM>simpler</EM> than another rational number <VAR>r2</VAR> if
<A NAME="IDX402"></A>
<DL COMPACT>
<DT><CODE>(= r1 (/ p1 q1))</CODE> and
<DD><DT><CODE>(= r2 (/ p2 q2))</CODE> (in lowest terms) and
<DD><DT><CODE>(&#60;= (abs p1) (abs p2))</CODE> and
<DD><DT><CODE>(&#60;= (abs q1) (abs q2))</CODE>.
<DD></DL>
Thus <CODE>(3/5)</CODE> is simpler than <CODE>(4/7)</CODE>.  Although not all
rationals are comparable in this ordering (consider <CODE>(2/7)</CODE> and
<CODE>(3/5)</CODE>) any interval contains a rational number that is simpler
than every other rational number in that interval (the simpler
<CODE>(2/5)</CODE> lies between <CODE>(2/7)</CODE> and <CODE>(3/5)</CODE>).  Note that 0
(<CODE>0/1</CODE>) is the simplest rational of all.
<P>
<PRE>
(rationalize
  (inexact-&#62;exact .3) 1/10)  =>  1/3    ; exact
(rationalize .3 1/10)        =>  #i1/3  ; inexact
</PRE>
<P>
<A NAME="IDX403"></A>
<U>procedure:</U> <B>exp</B> <I>z</I><P>
<A NAME="IDX404"></A>
<U>procedure:</U> <B>log</B> <I>z</I><P>
<A NAME="IDX405"></A>
<U>procedure:</U> <B>sin</B> <I>z</I><P>
<A NAME="IDX406"></A>
<U>procedure:</U> <B>cos</B> <I>z</I><P>
<A NAME="IDX407"></A>
<U>procedure:</U> <B>tan</B> <I>z</I><P>
<A NAME="IDX408"></A>
<U>procedure:</U> <B>asin</B> <I>z</I><P>
<A NAME="IDX409"></A>
<U>procedure:</U> <B>acos</B> <I>z</I><P>
<A NAME="IDX410"></A>
<U>procedure:</U> <B>atan</B> <I>z</I><P>
<A NAME="IDX411"></A>
<U>procedure:</U> <B>atan</B> <I>y x</I><P>
<P>
These procedures are part of every implementation that supports
general
real numbers; they compute the usual transcendental functions.
<CODE>Log</CODE>
<A NAME="IDX412"></A>
computes the natural logarithm of <VAR>z</VAR> (not the base ten logarithm).
<CODE>Asin</CODE>, <CODE>acos</CODE>, and <CODE>atan</CODE> compute arcsine
<A NAME="IDX414"></A>
<A NAME="IDX415"></A>
<A NAME="IDX413"></A>
, arccosine
, and arctangent
, respectively.
The two-argument variant of <CODE>atan</CODE> computes <CODE>(angle
(make-rectangular <VAR>x</VAR> <VAR>y</VAR>))</CODE> (see below), even in
implementations that don't support general complex numbers.
<A NAME="IDX416"></A>
<P>
In general, the mathematical functions log, arcsine, arccosine, and
arctangent are multiply defined.
For nonzero real <VAR>x</VAR>, the value of
<CODE>(log x)</CODE> is defined to be
the one whose imaginary part lies in the range 
<CODE>-pi</CODE> (exclusive) to <CODE>pi</CODE> (inclusive).  <CODE>(log 0)</CODE> is
undefined.  The value of <CODE>(log z)</CODE> when <VAR>z</VAR> is complex is
defined according to the formula
<P>
<PRE>
<TT>(define (log z) (+ (log (magnitude z)) (* +i (angle z))))</TT>
</PRE>
<P>
With <CODE>(log)</CODE> defined this way, the values of <CODE>arcsin</CODE>,
<CODE>arccos</CODE>, and <CODE>arctan</CODE> are according to the following
formulae:
<P>
<PRE>
<TT>(define (asin z) (* -i (log (+ (* +i z) (sqrt (- 1 (* z z)))))))</TT>

<TT>(define (acos z) (- (/ pi 2) (asin z)))</TT>

<TT>(define (atan z) (/ (log (/ (+ 1 (* +i z)) (- 1 (* +i z)))) (* +i 2))</TT>
</PRE>
<P>
The above specification follows [CLTL], which in turn
cites [PENFIELD81]; refer to these sources for more detailed
discussion of branch cuts, boundary conditions, and implementation of
these functions.  When it is possible these procedures produce a real
result from a real argument.
<P>
<A NAME="IDX417"></A>
<U>procedure:</U> <B>sqrt</B> <I>z</I><P>
<P>
Returns the principal square root of <VAR>z</VAR>.  The result will have
either positive real part, or zero real part and non-negative imaginary
part.
<P>
<A NAME="IDX418"></A>
<U>procedure:</U> <B>expt</B> <I>z1 z2</I><P>
<P>
Returns <VAR>z1</VAR> raised to the power <VAR>z2</VAR>:
<P>
<PRE>
(define (expt z1 z2) (exp z2 (log z1)))
</PRE>
<P>
<CODE>(expt 0 0)</CODE> is defined to be equal to 1.
<P>
<A NAME="IDX419"></A>
<U>procedure:</U> <B>make-rectangular</B> <I>x1 x2</I><P>
<A NAME="IDX420"></A>
<U>procedure:</U> <B>make-polar</B> <I>x3 x4</I><P>
<A NAME="IDX421"></A>
<U>procedure:</U> <B>real-part</B> <I>z</I><P>
<A NAME="IDX422"></A>
<U>procedure:</U> <B>imag-part</B> <I>z</I><P>
<A NAME="IDX423"></A>
<U>procedure:</U> <B>magnitude</B> <I>z</I><P>
<A NAME="IDX424"></A>
<U>procedure:</U> <B>angle</B> <I>z</I><P>
<P>
These procedures are part of every implementation that supports
general complex numbers.  Suppose <VAR>x1</VAR>, <VAR>x2</VAR>, <VAR>x3</VAR>, and
<VAR>x4</VAR> are real numbers and <VAR>z</VAR> is a complex number such that
<P>
<CODE>(= z (+ x1 (* +i x2) (* x3 (exp (* +i x4)))))</CODE>
<P>
Then <CODE>make-rectangular</CODE> and <CODE>make-polar</CODE> return <VAR>z</VAR>,
<A NAME="IDX426"></A>
<A NAME="IDX425"></A>
<CODE>real-part</CODE> returns <VAR>x1</VAR>, <CODE>imag-part</CODE> returns <VAR>x2</VAR>,
<A NAME="IDX428"></A>
<A NAME="IDX427"></A>
<CODE>magnitude</CODE> returns <VAR>x3</VAR>, and <CODE>angle</CODE> returns <VAR>x4</VAR>.
<A NAME="IDX430"></A>
<A NAME="IDX429"></A>
In the case of <CODE>angle</CODE>, whose value is not uniquely determined by
the preceding rule, the value returned will be the one in the range
<CODE>-pi</CODE> (exclusive) to <CODE>pi</CODE> (inclusive).
<P>
<EM>Rationale:</EM>  <CODE>Magnitude</CODE> is the same as <CODE>abs</CODE> for a real argument,
<A NAME="IDX432"></A>
<A NAME="IDX431"></A>
but <CODE>abs</CODE> must be present in all implementations, whereas
<A NAME="IDX433"></A>
<CODE>magnitude</CODE> need only be present in implementations that support
<A NAME="IDX434"></A>
general complex numbers.
<P>
<A NAME="IDX435"></A>
<U>procedure:</U> <B>exact-&#62;inexact</B> <I>z</I><P>
<A NAME="IDX436"></A>
<U>procedure:</U> <B>inexact-&#62;exact</B> <I>z</I><P>
<P>
<CODE>Exact-&#62;inexact</CODE> returns an inexact representation of
<VAR>z</VAR>.
<A NAME="IDX437"></A>
The value returned is the
inexact number that is numerically closest to the argument.
If an exact argument has no reasonably close inexact equivalent,
then a violation of an implementation restriction may be reported.
<P>
<CODE>Inexact-&#62;exact</CODE> returns an exact representation of
<A NAME="IDX438"></A>
<VAR>z</VAR>.  The value returned is the exact number that is numerically
closest to the argument.
If an inexact argument has no reasonably close exact equivalent,
then a violation of an implementation restriction may be reported.
<P>
These procedures implement the natural one-to-one correspondence between
exact and inexact integers throughout an
implementation-dependent range.  See section <A HREF="r4rs_8.htm#SEC53">Implementation restrictions</A>.
<P>
<H3><A NAME="SEC56" HREF="r4rs_toc.htm#SEC56">Numerical input and output</A></H3>
<P>
<A NAME="IDX439"></A>
<U>essential procedure:</U> <B>number-&#62;string</B> <I>number</I><P>
<A NAME="IDX440"></A>
<U>essential procedure:</U> <B>number-&#62;string</B> <I>number radix</I><P>
<P>
<VAR>Radix</VAR> must be an exact integer, either 2, 8, 10, or 16.  If omitted,
<VAR>radix</VAR> defaults to 10.
The procedure <CODE>number-&#62;string</CODE> takes a
<A NAME="IDX441"></A>
number and a radix and returns as a string an external representation of
the given number in the given radix such that
<PRE>
(let ((number <VAR>number</VAR>)
      (radix <VAR>radix</VAR>))
  (eqv? number
        (string-&#62;number (number-&#62;string number
                                        radix)
                        radix)))
</PRE>
is true.  It is an error if no possible result makes this expression true.
<P>
If <VAR>number</VAR> is inexact, the radix is 10, and the above expression
can be satisfied by a result that contains a decimal point,
then the result contains a decimal point and is expressed using the
minimum number of digits (exclusive of exponent and trailing
zeroes) needed to make the above expression
true [HOWTOPRINT], [HOWTOREAD];
otherwise the format of the result is unspecified.
<P>
The result returned by <CODE>number-&#62;string</CODE>
<A NAME="IDX442"></A>
never contains an explicit radix prefix.
<P>
<EM>Note:</EM>  The error case can occur only when <VAR>number</VAR> is not a complex number
or is a complex number with a non-rational real or imaginary part.
<P>
<EM>Rationale:</EM>  If <VAR>number</VAR> is an inexact number represented using flonums, and
the radix is 10, then the above expression is normally satisfied by
a result containing a decimal point.  The unspecified case
allows for infinities, NaNs, and non-flonum representations.
<P>
<A NAME="IDX443"></A>
<U>essential procedure:</U> <B>string-&#62;number</B> <I>string</I><P>
<A NAME="IDX444"></A>
<U>essential procedure:</U> <B>string-&#62;number</B> <I>string radix</I><P>
<P>
Returns a number of the maximally precise representation expressed by the
given <VAR>string</VAR>.  <VAR>Radix</VAR> must be an exact integer, either 2, 8, 10,
or 16.  If supplied, <VAR>radix</VAR> is a default radix that may be overridden
by an explicit radix prefix in <VAR>string</VAR> (e.g. <CODE>"#o177"</CODE>).  If <VAR>radix</VAR>
is not supplied, then the default radix is 10.  If <VAR>string</VAR> is not
a syntactically valid notation for a number, then <CODE>string-&#62;number</CODE>
<A NAME="IDX445"></A>
returns <CODE>#f</CODE>.
<P>
<PRE>
(string-&#62;number "100")      =>  100
(string-&#62;number "100" 16)   =>  256
(string-&#62;number "1e2")      =>  100.0
(string-&#62;number "15##")     =>  1500.0
</PRE>
<P>
<EM>Note:</EM>  Although <CODE>string-&#62;number</CODE> is an essential procedure,
<A NAME="IDX446"></A>
an implementation may restrict its domain in the
following ways.  <CODE>String-&#62;number</CODE> is permitted to return
<A NAME="IDX447"></A>
<CODE>#f</CODE> whenever <VAR>string</VAR> contains an explicit radix prefix.
If all numbers supported by an implementation are real, then
<CODE>string-&#62;number</CODE> is permitted to return <CODE>#f</CODE> whenever
<A NAME="IDX448"></A>
<VAR>string</VAR> uses the polar or rectangular notations for complex
numbers.  If all numbers are integers, then
<CODE>string-&#62;number</CODE> may return <CODE>#f</CODE> whenever
<A NAME="IDX449"></A>
the fractional notation is used.  If all numbers are exact, then
<CODE>string-&#62;number</CODE> may return <CODE>#f</CODE> whenever
<A NAME="IDX450"></A>
an exponent marker or explicit exactness prefix is used, or if
a <CODE>#</CODE> appears in place of a digit.  If all inexact
numbers are integers, then
<CODE>string-&#62;number</CODE> may return <CODE>#f</CODE> whenever
<A NAME="IDX451"></A>
a decimal point is used.
<P>
<H2><A NAME="SEC57" HREF="r4rs_toc.htm#SEC57">Characters</A></H2>
<P>
Characters are objects that represent printed characters such as
letters and digits.
Characters are written using the notation <TT>#\</TT>&#60;character&#62;
or <TT>#\</TT>&#60;character name&#62;.
For example:
<P>
<DL COMPACT>
<DT><CODE>#\a</CODE>
<DD>lower case letter
<DT><CODE>#\A</CODE>
<DD>upper case letter
<DT><CODE>#\(</CODE>
<DD>left parenthesis
<DT><CODE>#\</CODE>
<DD>the space character
<DT><CODE>#\space</CODE>
<DD>the preferred way to write a space
<DT><CODE>#\newline</CODE>
<DD>the newline character
</DL>
<P>
Case is significant in <TT>#\</TT>&#60;character&#62;, but not in
<TT>#\</TT>&#60;character name&#62;.  If &#60;character&#62; in
<TT>#\</TT>&#60;character&#62; is alphabetic, then the character
following &#60;character&#62; must be a delimiter character such as a
space or parenthesis.  This rule resolves the ambiguous case where, for
example, the sequence of characters "<CODE>#\space</CODE>"
could be taken to be either a representation of the space character or a
representation of the character "<CODE>#\s</CODE>" followed
by a representation of the symbol "<CODE>pace</CODE>."
<P>
Characters written in the <TT>#\</TT> notation are self-evaluating.
That is, they do not have to be quoted in programs.
<P>
Some of the procedures that operate on characters ignore the difference
between upper case and lower case.  The procedures that ignore case have
"<CODE>-ci</CODE>" (for "case insensitive") embedded in their names.
<P>
<A NAME="IDX452"></A>
<U>essential procedure:</U> <B>char?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a character, otherwise returns <CODE>#f</CODE>.
<P>
<A NAME="IDX453"></A>
<U>essential procedure:</U> <B>char=?</B> <I>char1 char2</I><P>
<A NAME="IDX454"></A>
<U>essential procedure:</U> <B>char&#60;?</B> <I>char1 char2</I><P>
<A NAME="IDX455"></A>
<U>essential procedure:</U> <B>char&#62;?</B> <I>char1 char2</I><P>
<A NAME="IDX456"></A>
<U>essential procedure:</U> <B>char&#60;=?</B> <I>char1 char2</I><P>
<A NAME="IDX457"></A>
<U>essential procedure:</U> <B>char&#62;=?</B> <I>char1 char2</I><P>
<P>
These procedures impose a total ordering on the set of characters.  It
is guaranteed that under this ordering:
<P>
<UL>
<LI>The upper case characters are in order.  For example,
<CODE>(char&#60;? #\A #\B)</CODE> returns <CODE>#t</CODE>.
<LI>The lower case characters are in order.  For example,
<CODE>(char&#60;? #\a #\b)</CODE> returns <CODE>#t</CODE>.
<LI>The digits are in order.  For example,
<CODE>(char&#60;? #\0 #\9)</CODE> returns <CODE>#t</CODE>.
<LI>Either all the digits precede all the upper case letters, or vice versa.
<LI>Either all the digits precede all the lower case letters, or vice versa.
</UL>
<P>
Some implementations may generalize these procedures to take more than
two arguments, as with the corresponding numerical predicates.
<P>
<A NAME="IDX458"></A>
<U>essential procedure:</U> <B>char-ci=?</B> <I>char1 char2</I><P>
<A NAME="IDX459"></A>
<U>essential procedure:</U> <B>char-ci&#60;?</B> <I>char1 char2</I><P>
<A NAME="IDX460"></A>
<U>essential procedure:</U> <B>char-ci&#62;?</B> <I>char1 char2</I><P>
<A NAME="IDX461"></A>
<U>essential procedure:</U> <B>char-ci&#60;=?</B> <I>char1 char2</I><P>
<A NAME="IDX462"></A>
<U>essential procedure:</U> <B>char-ci&#62;=?</B> <I>char1 char2</I><P>
<P>
These procedures are similar to <CODE>char=?</CODE> et cetera, but they treat
<A NAME="IDX463"></A>
upper case and lower case letters as the same.  For example,
<CODE>(char-ci=? #\A #\a)</CODE> returns <CODE>#t</CODE>.
Some implementations may generalize these procedures to take more than
two arguments, as with the corresponding numerical predicates.
<P>
<A NAME="IDX464"></A>
<U>essential procedure:</U> <B>char-alphabetic?</B> <I>char</I><P>
<A NAME="IDX465"></A>
<U>essential procedure:</U> <B>char-numeric?</B> <I>char</I><P>
<A NAME="IDX466"></A>
<U>essential procedure:</U> <B>char-whitespace?</B> <I>char</I><P>
<A NAME="IDX467"></A>
<U>essential procedure:</U> <B>char-upper-case?</B> <I>letter</I><P>
<A NAME="IDX468"></A>
<U>essential procedure:</U> <B>char-lower-case?</B> <I>letter</I><P>
<P>
These procedures return <CODE>#t</CODE> if their arguments are alphabetic,
numeric, whitespace, upper case, or lower case characters, respectively,
otherwise they return <CODE>#f</CODE>.  The following remarks, which are specific to
the ASCII character set, are intended only as a guide:  The alphabetic characters
are the 52 upper and lower case letters.  The numeric characters are the
ten decimal digits.  The whitespace characters are space, tab, line
feed, form feed, and carriage return.
<P>
<A NAME="IDX469"></A>
<U>essential procedure:</U> <B>char-&#62;integer</B> <I>char</I><P>
<A NAME="IDX470"></A>
<U>essential procedure:</U> <B>integer-&#62;char</B> <I>n</I><P>
<P>
Given a character, <CODE>char-&#62;integer</CODE> returns an exact integer
<A NAME="IDX471"></A>
representation of the character.  Given an exact integer that is the image of
a character under <CODE>char-&#62;integer</CODE>, <CODE>integer-&#62;char</CODE>
<A NAME="IDX473"></A>
<A NAME="IDX472"></A>
returns that character.  These procedures implement injective order isomorphisms
between the set of characters under the <CODE>char&#60;=?</CODE>
<A NAME="IDX474"></A>
ordering and some subset of the integers under the <CODE>&#60;=</CODE>
<A NAME="IDX475"></A>
ordering.  That is, if
<CODE>(char&#60;=? <VAR>a</VAR> <VAR>b</VAR>) => #t  and  (&#60;= <VAR>x</VAR> <VAR>y</VAR>) => #t</CODE>
and <VAR>x</VAR> and <VAR>y</VAR> are in the domain of
<CODE>integer-&#62;char</CODE>, then
<A NAME="IDX476"></A>
<P>
<PRE>
(&#60;= (char-&#62;integer <VAR>a</VAR>)
    (char-&#62;integer <VAR>b</VAR>))       =>  #t

(char&#60;=? (integer-&#62;char <VAR>x</VAR>)
         (integer-&#62;char <VAR>y</VAR>))  =>  #t
</PRE>
<P>
<A NAME="IDX477"></A>
<U>essential procedure:</U> <B>char-upcase</B> <I>char</I><P>
<A NAME="IDX478"></A>
<U>essential procedure:</U> <B>char-downcase</B> <I>char</I><P>
<P>
These procedures return a character <VAR>char2</VAR> such that <CODE>
(char-ci=? <VAR>char</VAR> <VAR>char2</VAR>)</CODE>.  In addition, if <VAR>char</VAR> is
alphabetic, then the result of <CODE>char-upcase</CODE> is upper case and the
<A NAME="IDX479"></A>
result of <CODE>char-downcase</CODE> is lower case.
<A NAME="IDX480"></A>
<P>
<H2><A NAME="SEC58" HREF="r4rs_toc.htm#SEC58">Strings</A></H2>
<P>
Strings are sequences of characters.
<A NAME="IDX481"></A>
Strings are written as sequences of characters enclosed within doublequotes
(<CODE>"</CODE>).  A doublequote can be written inside a string only by escaping
it with a backslash (<TT>\</TT>), as in
<P>
<PRE>
"The word \"recursion\" has many meanings."
</PRE>
<P>
A backslash can be written inside a string only by escaping it with another
backslash.  Scheme does not specify the effect of a backslash within a
string that is not followed by a doublequote or backslash.
<P>
A string constant may continue from one line to the next, but
the exact contents of such a string are unspecified.
<P>
The <EM>length</EM> of a string is the number of characters that it
contains.  This number is a non-negative integer that is fixed when the
string is created.  The <DFN>valid indexes</DFN> of a string are the
exact non-negative integers less than the length of the string.  The first
character of a string has index 0, the second has index 1, and so on.
<P>
In phrases such as "the characters of <VAR>string</VAR> beginning with
index <VAR>start</VAR> and ending with index <VAR>end</VAR>," it is understood
that the index <VAR>start</VAR> is inclusive and the index <VAR>end</VAR> is
exclusive.  Thus if <VAR>start</VAR> and <VAR>end</VAR> are the same index, a null
substring is referred to, and if <VAR>start</VAR> is zero and <VAR>end</VAR> is
the length of <VAR>string</VAR>, then the entire string is referred to.
<P>
Some of the procedures that operate on strings ignore the
difference between upper and lower case.  The versions that ignore case
have "<CODE>-ci</CODE>" (for "case insensitive") embedded in their
names.
<P>
<A NAME="IDX482"></A>
<U>essential procedure:</U> <B>string?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a string, otherwise returns <CODE>#f</CODE>.
<P>
<A NAME="IDX483"></A>
<U>essential procedure:</U> <B>make-string</B> <I>k</I><P>
<A NAME="IDX484"></A>
<U>essential procedure:</U> <B>make-string</B> <I>k char</I><P>
<P>
<CODE>Make-string</CODE> returns a newly allocated string of
<A NAME="IDX485"></A>
length <VAR>k</VAR>.  If <VAR>char</VAR> is given, then all elements of the string
are initialized to <VAR>char</VAR>, otherwise the contents of the
<VAR>string</VAR> are unspecified.
<P>
<A NAME="IDX486"></A>
<U>essential procedure:</U> <B>string</B> <I>char ...</I><P>
<P>
Returns a newly allocated string composed of the arguments.
<P>
<A NAME="IDX487"></A>
<U>essential procedure:</U> <B>string-length</B> <I>string</I><P>
<P>
Returns the number of characters in the given <VAR>string</VAR>.
<P>
<A NAME="IDX488"></A>
<U>essential procedure:</U> <B>string-ref</B> <I>string k</I><P>
<P>
<VAR>k</VAR> must be a valid index of <VAR>string</VAR>.
<CODE>String-ref</CODE> returns character <VAR>k</VAR> of <VAR>string</VAR> using
zero-origin indexing.
<A NAME="IDX489"></A>
<P>
<A NAME="IDX490"></A>
<U>essential procedure:</U> <B>string-set!</B> <I>string k char</I><P>
<P>
<VAR>k</VAR> must be a valid index of <VAR>string</VAR>%, and <VAR>char</VAR> must be a character
.
<CODE>String-set!</CODE> stores <VAR>char</VAR> in element <VAR>k</VAR> of <VAR>string</VAR>
<A NAME="IDX491"></A>
and returns an unspecified value.  
<P>
<PRE>
(define (f) (make-string 3 #\*))
(define (g) "***")
(string-set! (f) 0 #\?)     =>  <EM>unspecified</EM>
(string-set! (g) 0 #\?)     =>  <EM>error</EM>
(string-set! (symbol-&#62;string 'immutable)
             0
             #\?)           =>  <EM>error</EM>
</PRE>
<P>
<A NAME="IDX492"></A>
<U>essential procedure:</U> <B>string=?</B> <I>string1 string2</I><P>
<A NAME="IDX493"></A>
<U>essential procedure:</U> <B>string-ci=?</B> <I>string1 string2</I><P>
<P>
Returns <CODE>#t</CODE> if the two strings are the same length and contain the same
characters in the same positions, otherwise returns <CODE>#f</CODE>.
<CODE>String-ci=?</CODE> treats
<A NAME="IDX494"></A>
upper and lower case letters as though they were the same character, but
<CODE>string=?</CODE> treats upper and lower case as distinct characters.
<A NAME="IDX495"></A>
<P>
<A NAME="IDX496"></A>
<U>essential procedure:</U> <B>string&#60;?</B> <I>string1 string2</I><P>
<A NAME="IDX497"></A>
<U>essential procedure:</U> <B>string&#62;?</B> <I>string1 string2</I><P>
<A NAME="IDX498"></A>
<U>essential procedure:</U> <B>string&#60;=?</B> <I>string1 string2</I><P>
<A NAME="IDX499"></A>
<U>essential procedure:</U> <B>string&#62;=?</B> <I>string1 string2</I><P>
<A NAME="IDX500"></A>
<U>essential procedure:</U> <B>string-ci&#60;?</B> <I>string1 string2</I><P>
<A NAME="IDX501"></A>
<U>essential procedure:</U> <B>string-ci&#62;?</B> <I>string1 string2</I><P>
<A NAME="IDX502"></A>
<U>essential procedure:</U> <B>string-ci&#60;=?</B> <I>string1 string2</I><P>
<A NAME="IDX503"></A>
<U>essential procedure:</U> <B>string-ci&#62;=?</B> <I>string1 string2</I><P>
<P>
These procedures are the lexicographic extensions to strings of the
corresponding orderings on characters.  For example, <CODE>string&#60;?</CODE> is
<A NAME="IDX504"></A>
the lexicographic ordering on strings induced by the ordering
<CODE>char&#60;?</CODE> on characters.  If two strings differ in length but
<A NAME="IDX505"></A>
are the same up to the length of the shorter string, the shorter string
is considered to be lexicographically less than the longer string.
<P>
Implementations may generalize these and the <CODE>string=?</CODE> and
<A NAME="IDX506"></A>
<CODE>string-ci=?</CODE> procedures to take more than two arguments, as with
<A NAME="IDX507"></A>
the corresponding numerical predicates.
<P>
<A NAME="IDX508"></A>
<U>essential procedure:</U> <B>substring</B> <I>string start end</I><P>
<P>
<VAR>String</VAR> must be a string, and <VAR>start</VAR> and <VAR>end</VAR>
must be exact integers satisfying
<P>
<CODE>(&#60;= 0 <I>start</I> <I>end</I> (string-length <I>string</I>).)</CODE>
<P>
<CODE>Substring</CODE> returns a newly allocated string formed from the
characters of
<A NAME="IDX509"></A>
<VAR>string</VAR> beginning with index <VAR>start</VAR> (inclusive) and ending with index
<VAR>end</VAR> (exclusive).
<P>
<A NAME="IDX510"></A>
<U>essential procedure:</U> <B>string-append</B> <I>string ...</I><P>
<P>
Returns a newly allocated string whose characters form the concatenation of the
given strings.
<P>
<A NAME="IDX511"></A>
<U>essential procedure:</U> <B>string-&#62;list</B> <I>string</I><P>
<A NAME="IDX512"></A>
<U>essential procedure:</U> <B>list-&#62;string</B> <I>chars</I><P>
<P>
<CODE>String-&#62;list</CODE> returns a newly allocated list of the
<A NAME="IDX513"></A>
characters that make up the given string.  <CODE>List-&#62;string</CODE>
<A NAME="IDX514"></A>
returns a newly allocated string formed from the characters in the list
<VAR>chars</VAR>. <CODE>String-&#62;list</CODE> and <CODE>list-&#62;string</CODE> are
<A NAME="IDX516"></A>
<A NAME="IDX515"></A>
inverses so far as <CODE>equal?</CODE> is concerned.
<A NAME="IDX517"></A>
<P>
<A NAME="IDX518"></A>
<U>procedure:</U> <B>string-copy</B> <I>string</I><P>
<P>
Returns a newly allocated copy of the given <VAR>string</VAR>.
<P>
<A NAME="IDX519"></A>
<U>procedure:</U> <B>string-fill!</B> <I>string char</I><P>
<P>
Stores <VAR>char</VAR> in every element of the given <VAR>string</VAR> and returns an
unspecified value.  
<P>
<H2><A NAME="SEC59" HREF="r4rs_toc.htm#SEC59">Vectors</A></H2>
<P>
Vectors are heterogenous structures whose elements are indexed
by integers.  A vector typically occupies less space than a list
of the same length, and the average time required to access a randomly
chosen element is typically less for the vector than for the list.
<P>
The <EM>length</EM> of a vector is the number of elements that it
contains.  This number is a non-negative integer that is fixed when the
vector is created.  The <EM>valid indexes</EM>
<A NAME="IDX520"></A>
of a vector are the exact non-negative integers less than the length of
the vector.  The first element in a vector is indexed by zero, and the
last element is indexed by one less than the length of the vector.
<P>
Vectors are written using the notation <CODE>#(<VAR>obj</VAR> ...)</CODE>.
For example, a vector of length 3 containing the number zero in element
0, the list <CODE>(2 2 2 2)</CODE> in element 1, and the string <CODE>"Anna"</CODE> in
element 2 can be written as following:
<P>
<PRE>
#(0 (2 2 2 2) "Anna")
</PRE>
<P>
Note that this is the external representation of a vector, not an
expression evaluating to a vector.  Like list constants, vector
constants must be quoted:
<P>
<PRE>
'#(0 (2 2 2 2) "Anna")  
          =>  #(0 (2 2 2 2) "Anna")
</PRE>
<P>
<A NAME="IDX521"></A>
<U>essential procedure:</U> <B>vector?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a vector, otherwise returns <CODE>#f</CODE>.
<P>
<A NAME="IDX522"></A>
<U>essential procedure:</U> <B>make-vector</B> <I>k</I><P>
<A NAME="IDX523"></A>
<U>procedure:</U> <B>make-vector</B> <I>k fill</I><P>
<P>
Returns a newly allocated vector of <VAR>k</VAR> elements.  If a second
argument is given, then each element is initialized to <VAR>fill</VAR>.
Otherwise the initial contents of each element is unspecified.
<P>
<A NAME="IDX524"></A>
<U>essential procedure:</U> <B>vector</B> <I>obj ...</I><P>
<P>
Returns a newly allocated vector whose elements contain the given
arguments.  Analogous to <CODE>list</CODE>.
<A NAME="IDX525"></A>
<P>
<PRE>
(vector 'a 'b 'c)           =>  #(a b c)
</PRE>
<P>
<A NAME="IDX526"></A>
<U>essential procedure:</U> <B>vector-length</B> <I>vector</I><P>
<P>
Returns the number of elements in <VAR>vector</VAR>.
<P>
<A NAME="IDX527"></A>
<U>essential procedure:</U> <B>vector-ref</B> <I>vector k</I><P>
<P>
<VAR>k</VAR> must be a valid index of <VAR>vector</VAR>.
<CODE>Vector-ref</CODE> returns the contents of element <VAR>k</VAR> of
<A NAME="IDX528"></A>
<VAR>vector</VAR>.
<P>
<PRE>
(vector-ref '#(1 1 2 3 5 8 13 21)
            5)  
          =>  8
(vector-ref '#(1 1 2 3 5 8 13 21)
            (inexact-&#62;exact
              (round (* 2 (acos -1))))) 
          =>  13
</PRE>
<P>
<A NAME="IDX529"></A>
<U>essential procedure:</U> <B>vector-set!</B> <I>vector k obj</I><P>
<P>
<VAR>k</VAR> must be a valid index of <VAR>vector</VAR>.
<CODE>Vector-set!</CODE> stores <VAR>obj</VAR> in element <VAR>k</VAR> of <VAR>vector</VAR>.
<A NAME="IDX530"></A>
The value returned by <CODE>vector-set!</CODE> is unspecified.  
<A NAME="IDX531"></A>
<P>
<PRE>
(let ((vec (vector 0 '(2 2 2 2) "Anna")))
  (vector-set! vec 1 '("Sue" "Sue"))
  vec)      
          =>  #(0 ("Sue" "Sue") "Anna")

(vector-set! '#(0 1 2) 1 "doe")  
          =>  <EM>error</EM>  ; constant vector
</PRE>
<P>
<A NAME="IDX532"></A>
<U>essential procedure:</U> <B>vector-&#62;list</B> <I>vector</I><P>
<A NAME="IDX533"></A>
<U>essential procedure:</U> <B>list-&#62;vector</B> <I>list</I><P>
<P>
<CODE>Vector-&#62;list</CODE> returns a newly allocated list of the objects
contained
<A NAME="IDX534"></A>
in the elements of <VAR>vector</VAR>.  <CODE>List-&#62;vector</CODE> returns a newly
<A NAME="IDX535"></A>
created vector initialized to the elements of the list <VAR>list</VAR>.
<P>
<PRE>
(vector-&#62;list '#(dah dah didah))  
          =>  (dah dah didah)
(list-&#62;vector '(dididit dah))   
          =>  #(dididit dah)
</PRE>
<P>
<A NAME="IDX536"></A>
<U>procedure:</U> <B>vector-fill!</B> <I>vector fill</I><P>
<P>
Stores <VAR>fill</VAR> in every element of <VAR>vector</VAR>.
The value returned by <CODE>vector-fill!</CODE> is unspecified.  
<A NAME="IDX537"></A>
<P>
<H2><A NAME="SEC60" HREF="r4rs_toc.htm#SEC60">Control features</A></H2>
<P>
This chapter describes various primitive procedures which control the
flow of program execution in special ways.
The <CODE>procedure?</CODE> predicate is also described here.
<A NAME="IDX538"></A>
<P>
<A NAME="IDX539"></A>
<U>essential procedure:</U> <B>procedure?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is a procedure, otherwise returns <CODE>#f</CODE>.
<P>
<PRE>
(procedure? car)            =>  #t
(procedure? 'car)           =>  #f
(procedure? (lambda (x) (* x x)))
                            =>  #t
(procedure? '(lambda (x) (* x x)))
                            =>  #f
(call-with-current-continuation procedure?)
                            =>  #t
</PRE>
<P>
<A NAME="IDX540"></A>
<U>essential procedure:</U> <B>apply</B> <I>proc args</I><P>
<A NAME="IDX541"></A>
<U>procedure:</U> <B>apply</B> <I>proc arg1 ... args</I><P>
<P>
<VAR>Proc</VAR> must be a procedure and <VAR>args</VAR> must be a list.
The first (essential) form calls <VAR>proc</VAR> with the elements of
<VAR>args</VAR> as the actual arguments.  The second form is a generalization
of the first that calls <VAR>proc</VAR> with the elements of the list
<CODE>(append (list <VAR>arg1</VAR> ...) <VAR>args</VAR>)</CODE> as the actual
arguments.
<P>
<PRE>
(apply + (list 3 4))        =>  7

(define compose
  (lambda (f g)
    (lambda args
      (f (apply g args)))))

((compose sqrt *) 12 75)    =>  30
</PRE>
<P>
<A NAME="IDX542"></A>
<U>essential procedure:</U> <B>map</B> <I>proc list1 list2 ...</I><P>
<P>
The <VAR>list</VAR>s must be lists, and <VAR>proc</VAR> must be a
procedure taking as many arguments as there are <I>list</I>s.  If more
than one <VAR>list</VAR> is given, then they must all be the same length.
<CODE>Map</CODE> applies <VAR>proc</VAR> element-wise to the elements of the
<A NAME="IDX543"></A>
<VAR>list</VAR>s and returns a list of the results, in order from left to right.
The dynamic order in which <VAR>proc</VAR> is applied to the elements of the
<VAR>list</VAR>s is unspecified.
<P>
<PRE>
(map cadr '((a b) (d e) (g h)))   
                            =>  (b e h)

(map (lambda (n) (expt n n))
     '(1 2 3 4 5))                
                            =>  (1 4 27 256 3125)

(map + '(1 2 3) '(4 5 6))   =>  (5 7 9)

(let ((count 0))
  (map (lambda (ignored)
         (set! count (+ count 1))
         count)
       '(a b c)))           =>  <EM>unspecified</EM>
</PRE>
<P>
<A NAME="IDX544"></A>
<U>essential procedure:</U> <B>for-each</B> <I>proc list1 list2 ...</I><P>
<P>
The arguments to <CODE>for-each</CODE> are like the arguments to <CODE>map</CODE>, but
<A NAME="IDX546"></A>
<A NAME="IDX545"></A>
<CODE>for-each</CODE> calls <VAR>proc</VAR> for its side effects rather than for
its values.  Unlike <CODE>map</CODE>, <CODE>for-each</CODE> is guaranteed to call
<VAR>proc</VAR> on the elements of the <VAR>list</VAR>s in order from the first
element to the last, and the value returned by <CODE>for-each</CODE> is
unspecified.
<P>
<PRE>
(let ((v (make-vector 5)))
  (for-each (lambda (i)
              (vector-set! v i (* i i)))
            '(0 1 2 3 4))
  v)                        =>  #(0 1 4 9 16)
</PRE>
<P>
<A NAME="IDX547"></A>
<U>procedure:</U> <B>force</B> <I>promise</I><P>
<P>
Forces the value of <VAR>promise</VAR> (see section <A HREF="r4rs_6.htm#SEC38">Delayed evaluation</A>).
<A NAME="IDX548"></A>
<A NAME="IDX549"></A>
<P>
If no value has been computed for the promise, then a value is computed
and returned.  The value of the promise is cached (or "memoized") so
that if it is forced a second time, the previously computed value is
returned.
<P>
<PRE>
(force (delay (+ 1 2)))     =>  3
(let ((p (delay (+ 1 2))))
  (list (force p) (force p)))
                            =>  (3 3)

(define a-stream
  (letrec ((next
            (lambda (n)
              (cons n (delay (next (+ n 1)))))))
    (next 0)))
(define head car)
(define tail
  (lambda (stream) (force (cdr stream))))

(head (tail (tail a-stream)))
                            =>  2
</PRE>
<P>
<CODE>Force</CODE> and <CODE>delay</CODE> are mainly intended for programs written
<A NAME="IDX551"></A>
<A NAME="IDX550"></A>
in functional style.  The following examples should not be considered to
illustrate good programming style, but they illustrate the property that
only one value is computed for a promise, no matter how many times it is
forced.
<P>
<PRE>
(define count 0)
(define p
  (delay (begin (set! count (+ count 1))
                (if (&#62; count x)
                    count
                    (force p)))))
(define x 5)
p                           =>  <EM>a promise</EM>
(force p)                   =>  6
p                           =>  <EM>a promise, still</EM>
(begin (set! x 10)
       (force p))           =>  6
</PRE>
<P>
Here is a possible implementation of <CODE>delay</CODE> and <CODE>force</CODE>.
<A NAME="IDX553"></A>
<A NAME="IDX552"></A>
Promises are implemented here as procedures of no arguments,
and <CODE>force</CODE> simply calls its argument:
<A NAME="IDX554"></A>
<P>
<PRE>
(define force
  (lambda (object)
    (object)))
</PRE>
<P>
We define the expression
<P>
<PRE>
(delay &#60;expression&#62;)
</PRE>
<P>
to have the same meaning as the procedure call
<P>
<PRE>
(make-promise (lambda () &#60;expression&#62;)),
</PRE>
<P>
where <CODE>make-promise</CODE> is defined as follows:
<A NAME="IDX555"></A>
<P>
<PRE>
(define make-promise
  (lambda (proc)
    (let ((result-ready? #f)
          (result #f))
      (lambda ()
        (if result-ready?
            result
            (let ((x (proc)))
              (if result-ready?
                  result
                  (begin (set! result-ready? #t)
                         (set! result x)
                         result))))))))
</PRE>
<P>
<EM>Rationale:</EM>  A promise may refer to its own value, as in the last example above.
Forcing such a promise may cause the promise to be forced a second time
before the value of the first force has been computed.
This complicates the definition of <CODE>make-promise</CODE>.
<A NAME="IDX556"></A>
<P>
Various extensions to this semantics of <CODE>delay</CODE> and <CODE>force</CODE>
<A NAME="IDX558"></A>
<A NAME="IDX557"></A>
are supported in some implementations:
<P>
<UL>
<A NAME="IDX559"></A>
<LI>Calling <CODE>force</CODE> on an object that is not a promise may simply
return the object.
<P>
<LI>It may be the case that there is no means by which a promise can be
operationally distinguished from its forced value.  That is, expressions
like the following may evaluate to either <CODE>#t</CODE> or to <CODE>#f</CODE>,
depending on the implementation:
<P>
<PRE>
(eqv? (delay 1) 1)          =>  <EM>unspecified</EM>
(pair? (delay (cons 1 2)))  =>  <EM>unspecified</EM>
</PRE>
<P>
<LI>Some implementations may implement "implicit forcing," where
the value of a promise is forced by primitive procedures like <CODE>cdr</CODE>
<A NAME="IDX560"></A>
and <CODE>+</CODE>:
<A NAME="IDX561"></A>
<P>
<PRE>
(+ (delay (* 3 7)) 13)      =>  34
</PRE>
</UL>
<P>
<A NAME="IDX562"></A>
<U>essential procedure:</U> <B>call-with-current-continuation</B> <I>proc</I><P>
<P>
<VAR>Proc</VAR> must be a procedure of one
argument. The procedure <CODE>call-with-current-continuation</CODE> packages
<A NAME="IDX563"></A>
up the current continuation (see the rationale below) as an "escape
procedure"
<A NAME="IDX564"></A>
and passes it as an argument to
<VAR>proc</VAR>.  The escape procedure is a Scheme procedure of one
argument that, if it is later passed a value, will ignore whatever
continuation is in effect at that later time and will give the value
instead to the continuation that was in effect when the escape procedure
was created.
<P>
The escape procedure that is passed to <VAR>proc</VAR> has
unlimited extent just like any other procedure in Scheme.  It may be stored
in variables or data structures and may be called as many times as desired.
<P>
The following examples show only the most common uses of
<CODE>call-with-current-continuation</CODE>.  If all real programs were as
<A NAME="IDX565"></A>
simple as these examples, there would be no need for a procedure with
the power of <CODE>call-with-current-continuation</CODE>.
<A NAME="IDX566"></A>
<P>
<PRE>
(call-with-current-continuation
  (lambda (exit)
    (for-each (lambda (x)
                (if (negative? x)
                    (exit x)))
              '(54 0 37 -3 245 19))
    #t))                    =>  -3

(define list-length
  (lambda (obj)
    (call-with-current-continuation
      (lambda (return)
        (letrec ((r
                  (lambda (obj)
                    (cond ((null? obj) 0)
                          ((pair? obj)
                           (+ (r (cdr obj)) 1))
                          (else (return #f))))))
          (r obj))))))

(list-length '(1 2 3 4))    =>  4

(list-length '(a b . c))    =>  #f
</PRE>
<P>
<EM>Rationale:</EM>  
A common use of <CODE>call-with-current-continuation</CODE> is for
<A NAME="IDX567"></A>
structured, non-local exits from loops or procedure bodies, but in fact
<CODE>call-with-current-continuation</CODE> is extremely useful for
implementing a
<A NAME="IDX568"></A>
wide variety of advanced control structures.
<P>
Whenever a Scheme expression is evaluated there is a
<DFN>continuation</DFN> wanting the result of the expression.  The continuation
represents an entire (default) future for the computation.  If the expression is
evaluated at top level, for example, then the continuation might take the
result, print it on the screen, prompt for the next input, evaluate it, and
so on forever.  Most of the time the continuation includes actions
specified by user code, as in a continuation that will take the result,
multiply it by the value stored in a local variable, add seven, and give
the answer to the top level continuation to be printed.  Normally these
ubiquitous continuations are hidden behind the scenes and programmers don't
think much about them.  On rare occasions, however, a programmer may
need to deal with continuations explicitly.
<CODE>Call-with-current-continuation</CODE> allows Scheme programmers to do
<A NAME="IDX569"></A>
that by creating a procedure that acts just like the current
continuation.
<P>
Most programming languages incorporate one or more special-purpose
escape constructs with names like <CODE>exit</CODE>, <CODE>return</CODE>, or
<A NAME="IDX570"></A>
even <CODE>goto</CODE>.  In 1965, however, Peter Landin [LANDIN65]
invented a general purpose escape operator called the J-operator.  John
Reynolds [REYNOLDS72] described a simpler but equally powerful
construct in 1972.  The <CODE>catch</CODE> special form described by Sussman
<A NAME="IDX571"></A>
and Steele in the 1975 report on Scheme is exactly the same as
Reynolds's construct, though its name came from a less general construct
in MacLisp.  Several Scheme implementors noticed that the full power of the
<CODE>catch</CODE> construct could be provided by a procedure instead of by a
<A NAME="IDX572"></A>
special syntactic construct, and the name
<CODE>call-with-current-continuation</CODE> was coined in 1982.  This name is
<A NAME="IDX573"></A>
descriptive, but opinions differ on the merits of such a long name, and
some people use the name <CODE>call/cc</CODE> instead.
<A NAME="IDX574"></A>
<P>
<H2><A NAME="SEC61" HREF="r4rs_toc.htm#SEC61">Input and output</A></H2>
<P>
<H3><A NAME="SEC62" HREF="r4rs_toc.htm#SEC62">Ports</A></H3>
<P>
Ports represent input and output devices.  To Scheme, an input port is a
Scheme object that can deliver characters upon command, while an output port
is a Scheme object that can accept characters.
<A NAME="IDX575"></A>
<P>
<A NAME="IDX576"></A>
<U>essential procedure:</U> <B>call-with-input-file</B> <I>string proc</I><P>
<A NAME="IDX577"></A>
<U>essential procedure:</U> <B>call-with-output-file</B> <I>string proc</I><P>
<P>
<VAR>Proc</VAR> should be a procedure of one argument, and
<VAR>string</VAR> should be a string naming a file.  For
<CODE>call-with-input-file</CODE>, the file must already exist; for
<A NAME="IDX578"></A>
<CODE>call-with-output-file</CODE>, the effect is unspecified if the file
<A NAME="IDX579"></A>
already exists. These procedures call <VAR>proc</VAR> with one argument: the
port obtained by opening the named file for input or output.  If the
file cannot be opened, an error is signalled.  If the procedure returns,
then the port is closed automatically and the value yielded by the
procedure is returned.  If the procedure does not return, then
the port will not be closed automatically unless it is possible to
prove that the port will never again be used for a read or write
operation.
<P>
<EM>Rationale:</EM>  Because Scheme's escape procedures have unlimited extent, it  is
possible to escape from the current continuation but later to escape back in.
If implementations were permitted to close the port on any escape from the
current continuation, then it would be impossible to write portable code using
both <CODE>call-with-current-continuation</CODE> and
<CODE>call-with-input-file</CODE> or <CODE>call-with-output-file</CODE>.
<A NAME="IDX581"></A>
<A NAME="IDX582"></A>
<A NAME="IDX580"></A>
<P>
<A NAME="IDX583"></A>
<U>essential procedure:</U> <B>input-port?</B> <I>obj</I><P>
<A NAME="IDX584"></A>
<U>essential procedure:</U> <B>output-port?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is an input port or output port
respectively, otherwise returns <CODE>#f</CODE>.
<P>
<A NAME="IDX585"></A>
<U>essential procedure:</U> <B>current-input-port</B><P>
<A NAME="IDX586"></A>
<U>essential procedure:</U> <B>current-output-port</B><P>
<P>
Returns the current default input or output port.
<P>
<A NAME="IDX587"></A>
<U>procedure:</U> <B>with-input-from-file</B> <I>string thunk</I><P>
<A NAME="IDX588"></A>
<U>procedure:</U> <B>with-output-to-file</B> <I>string thunk</I><P>
<P>
<VAR>Thunk</VAR> must be a procedure of no arguments, and
<VAR>string</VAR> must be a string naming a file.  For
<CODE>with-input-from-file</CODE>, the file must already exist; for
<A NAME="IDX589"></A>
<CODE>with-output-to-file</CODE>, the effect is unspecified if the file
already
<A NAME="IDX590"></A>
exists. The file is opened for input or output, an input or output port
connected to it is made the default value returned by
<CODE>current-input-port</CODE> or <CODE>current-output-port</CODE>, and the
<A NAME="IDX592"></A>
<A NAME="IDX591"></A>
<VAR>thunk</VAR> is called with no arguments.  When the <VAR>thunk</VAR> returns,
the port is closed and the previous default is restored.
<CODE>With-input-from-file</CODE> and <CODE>with-output-to-file</CODE> return the
<A NAME="IDX594"></A>
<A NAME="IDX593"></A>
value yielded by <VAR>thunk</VAR>.
If an escape procedure
is used to escape from the continuation of these procedures, their
behavior is implementation dependent.
<P>
<A NAME="IDX595"></A>
<U>essential procedure:</U> <B>open-input-file</B> <I>filename</I><P>
<P>
Takes a string naming an existing file and returns an input port capable of
delivering characters from the file.  If the file cannot be opened, an error is
signalled.
<P>
<A NAME="IDX596"></A>
<U>essential procedure:</U> <B>open-output-file</B> <I>filename</I><P>
<P>
Takes a string naming an output file to be created and returns an output
port capable of writing characters to a new file by that name.  If the file
cannot be opened, an error is signalled.  If a file with the given name
already exists, the effect is unspecified.
<P>
<A NAME="IDX597"></A>
<U>essential procedure:</U> <B>close-input-port</B> <I>port</I><P>
<A NAME="IDX598"></A>
<U>essential procedure:</U> <B>close-output-port</B> <I>port</I><P>
<P>
Closes the file associated with <VAR>port</VAR>, rendering the <VAR>port</VAR>
incapable of delivering or accepting characters.
<P>
These routines have no effect if the file has already been closed.
The value returned is unspecified.
<P>
<H3><A NAME="SEC63" HREF="r4rs_toc.htm#SEC63">Input</A></H3>
<P>
<A NAME="IDX599"></A>
<U>essential procedure:</U> <B>read</B><P>
<A NAME="IDX600"></A>
<U>essential procedure:</U> <B>read</B> <I>port</I><P>
<P>
<CODE>Read</CODE> converts external representations of Scheme objects into the
<A NAME="IDX601"></A>
objects themselves.  That is, it is a parser for the nonterminal
&#60;datum&#62; (see section <A HREF="r4rs_5.htm#SEC22">External representations</A> and
section <A HREF="r4rs_8.htm#SEC48">Pairs and lists</A>).  <CODE>Read</CODE> returns the next
object parsable from the given input <VAR>port</VAR>, updating <VAR>port</VAR> to point to
the first character past the end of the external representation of the object.
<P>
If an end of file is encountered in the input before any characters are
found that can begin an object, then an end of file object is returned.
The port remains open, and further attempts to read will also return an
end of file object.  If an end of file is encountered after the
beginning of an object's external representation, but the external
representation is incomplete and therefore not parsable, an error is
signalled.
<P>
The <VAR>port</VAR> argument may be omitted, in which case it defaults to the
value returned by <CODE>current-input-port</CODE>.  It is an error to read
from a closed port.
<A NAME="IDX602"></A>
<P>
<A NAME="IDX603"></A>
<U>essential procedure:</U> <B>read-char</B><P>
<A NAME="IDX604"></A>
<U>essential procedure:</U> <B>read-char</B> <I>port</I><P>
<P>
Returns the next character available from the input <VAR>port</VAR>, updating
the <VAR>port</VAR> to point to the following character.  If no more characters
are available, an end of file object is returned.  <VAR>Port</VAR> may be
omitted, in which case it defaults to the value returned by
<CODE>current-input-port</CODE>.
<A NAME="IDX605"></A>
<P>
<A NAME="IDX606"></A>
<U>essential procedure:</U> <B>peek-char</B><P>
<A NAME="IDX607"></A>
<U>essential procedure:</U> <B>peek-char</B> <I>port</I><P>
<P>
Returns the next character available from the input <VAR>port</VAR>,
<EM>without</EM> updating
the <VAR>port</VAR> to point to the following character.  If no more characters
are available, an end of file object is returned.  <VAR>Port</VAR> may be
omitted, in which case it defaults to the value returned by
<CODE>current-input-port</CODE>.
<A NAME="IDX608"></A>
<P>
<EM>Note:</EM>  The value returned by a call to <CODE>peek-char</CODE> is the same as the
<A NAME="IDX609"></A>
value that would have been returned by a call to <CODE>read-char</CODE> with
the
<A NAME="IDX610"></A>
same <VAR>port</VAR>.  The only difference is that the very next call to
<CODE>read-char</CODE> or <CODE>peek-char</CODE> on that <VAR>port</VAR> will return
<A NAME="IDX611"></A>
the
<A NAME="IDX612"></A>
value returned by the preceding call to <CODE>peek-char</CODE>.  In
particular, a call
<A NAME="IDX613"></A>
to <CODE>peek-char</CODE> on an interactive port will hang waiting for input
<A NAME="IDX614"></A>
whenever a call to <CODE>read-char</CODE> would have hung.
<A NAME="IDX615"></A>
<P>
<A NAME="IDX616"></A>
<U>essential procedure:</U> <B>eof-object?</B> <I>obj</I><P>
<P>
Returns <CODE>#t</CODE> if <VAR>obj</VAR> is an end of file object, otherwise returns
<CODE>#f</CODE>.  The precise set of end of file objects will vary among
implementations, but in any case no end of file object will ever be an object
that can be read in using <CODE>read</CODE>.
<A NAME="IDX617"></A>
<P>
<A NAME="IDX618"></A>
<U>procedure:</U> <B>char-ready?</B><P>
<A NAME="IDX619"></A>
<U>procedure:</U> <B>char-ready?</B> <I>port</I><P>
<P>
Returns <CODE>#t</CODE> if a character is ready on the input <VAR>port</VAR> and
returns <CODE>#f</CODE> otherwise.  If <CODE>char-ready</CODE> returns <CODE>#t</CODE>
then
<A NAME="IDX620"></A>
the next <CODE>read-char</CODE> operation on the given <VAR>port</VAR> is
guaranteed
<A NAME="IDX621"></A>
not to hang.  If the <VAR>port</VAR> is at end of file then
<CODE>char-ready?</CODE> returns <CODE>#t</CODE>.
<A NAME="IDX622"></A>
<VAR>Port</VAR> may be omitted, in which case it defaults to
the value returned by <CODE>current-input-port</CODE>.
<A NAME="IDX623"></A>
<P>
<EM>Rationale:</EM>  <CODE>Char-ready?</CODE> exists to make it possible for a program to
<A NAME="IDX624"></A>
accept characters from interactive ports without getting stuck waiting
for input.  Any input editors associated with such ports must ensure
that characters whose existence has been asserted by <CODE>char-ready?</CODE>
<A NAME="IDX625"></A>
cannot be rubbed out.  If <CODE>char-ready?</CODE> were to return <CODE>#f</CODE> at
end of file, a port at end of file would be indistinguishable from an
interactive port that has no ready characters.
<P>
<H3><A NAME="SEC64" HREF="r4rs_toc.htm#SEC64">Output</A></H3>
<P>
<A NAME="IDX626"></A>
<U>essential procedure:</U> <B>write</B> <I>obj</I><P>
<A NAME="IDX627"></A>
<U>essential procedure:</U> <B>write</B> <I>obj port</I><P>
<P>
Writes a written representation of <VAR>obj</VAR> to the given <VAR>port</VAR>.  Strings
that appear in the written representation are enclosed in doublequotes, and
within those strings backslash and doublequote characters are
escaped by backslashes.  <CODE>Write</CODE> returns an unspecified value.  The
<A NAME="IDX628"></A>
<VAR>port</VAR> argument may be omitted, in which case it defaults to the value
returned by <CODE>current-output-port</CODE>.
<A NAME="IDX629"></A>
<P>
<A NAME="IDX630"></A>
<U>essential procedure:</U> <B>display</B> <I>obj</I><P>
<A NAME="IDX631"></A>
<U>essential procedure:</U> <B>display</B> <I>obj port</I><P>
<P>
Writes a representation of <VAR>obj</VAR> to the given <VAR>port</VAR>.  Strings
that appear in the written representation are not enclosed in
doublequotes, and no characters are escaped within those strings.  Character
objects appear in the representation as if written by <CODE>write-char</CODE>
<A NAME="IDX632"></A>
instead of by <CODE>write</CODE>.  <CODE>Display</CODE> returns an unspecified
<A NAME="IDX633"></A>
value.
<A NAME="IDX634"></A>
The <VAR>port</VAR> argument may be omitted, in which case it defaults to the
value returned by <CODE>current-output-port</CODE>.
<A NAME="IDX635"></A>
<P>
<EM>Rationale:</EM>  <CODE>Write</CODE> is intended
<A NAME="IDX636"></A>
for producing machine-readable output and <CODE>display</CODE> is for
producing
<A NAME="IDX637"></A>
human-readable output.  Implementations that allow "slashification"
within symbols will probably want <CODE>write</CODE> but not <CODE>display</CODE>
<A NAME="IDX638"></A>
to
<A NAME="IDX639"></A>
slashify funny characters in symbols.
<P>
<A NAME="IDX640"></A>
<U>essential procedure:</U> <B>newline</B><P>
<A NAME="IDX641"></A>
<U>essential procedure:</U> <B>newline</B> <I>port</I><P>
<P>
Writes an end of line to <VAR>port</VAR>.  Exactly how this is done differs
from one operating system to another.  Returns an unspecified value.
The <VAR>port</VAR> argument may be omitted, in which case it defaults to the
value returned by <CODE>current-output-port</CODE>.
<A NAME="IDX642"></A>
<P>
<A NAME="IDX643"></A>
<U>essential procedure:</U> <B>write-char</B> <I>char</I><P>
<A NAME="IDX644"></A>
<U>essential procedure:</U> <B>write-char</B> <I>char port</I><P>
<P>
Writes the character <VAR>char</VAR> (not an external representation of the
character) to the given <VAR>port</VAR> and returns an unspecified value.  The
<VAR>port</VAR> argument may be omitted, in which case it defaults to the value
returned by <CODE>current-output-port</CODE>.
<A NAME="IDX645"></A>
<P>
<H3><A NAME="SEC65" HREF="r4rs_toc.htm#SEC65">System interface</A></H3>
<P>
Questions of system interface generally fall outside of the domain of this
report.  However, the following operations are important enough to
deserve description here.
<P>
<A NAME="IDX646"></A>
<U>essential procedure:</U> <B>load</B> <I>filename</I><P>
<P>
<VAR>Filename</VAR> should be a string naming an existing file
containing Scheme source code. The <CODE>load</CODE> procedure reads
<A NAME="IDX647"></A>
expressions and definitions from the file and evaluates them
sequentially.  It is unspecified whether the results of the expressions
are printed.  The <CODE>load</CODE> procedure does not affect the values
<A NAME="IDX648"></A>
returned by <CODE>current-input-port</CODE> and <CODE>current-output-port</CODE>.
<A NAME="IDX650"></A>
<A NAME="IDX649"></A>
<CODE>Load</CODE> returns an unspecified value.
<A NAME="IDX651"></A>
<P>
<EM>Rationale:</EM>  For portability, <CODE>load</CODE> must operate on source files.
<A NAME="IDX652"></A>
Its operation on other kinds of files necessarily varies among
implementations.
<P>
<A NAME="IDX653"></A>
<U>procedure:</U> <B>transcript-on</B> <I>filename</I><P>
<A NAME="IDX654"></A>
<U>procedure:</U> <B>transcript-off</B><P>
<P>
<VAR>Filename</VAR> must be a string naming an output file to be
created. The effect of <CODE>transcript-on</CODE> is to open the named file
<A NAME="IDX655"></A>
for output, and to cause a transcript of subsequent interaction between
the user and the Scheme system to be written to the file.  The
transcript is ended by a call to <CODE>transcript-off</CODE>, which closes the
<A NAME="IDX656"></A>
transcript file.  Only one transcript may be in progress at any time,
though some implementations may relax this restriction.  The values
returned by these procedures are unspecified.
<P>
<P>Go to the <A HREF="r4rs_7.htm">previous</A>, <A HREF="r4rs_9.htm">next</A> section.<P>
&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>&nbsp;<p>